Force sensors and photocells

Submitted by vstarostenko on Tue, 02/26/2013 - 23:57

 

The below code reads input from a pressure sensor and passes the output to serial.
 
int potPin1 = 1;
int potValue = 0;  
int led9 = 9;      
 
 
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
  // declare the led pin as an output:
  pinMode(led9, OUTPUT);
 
}
 
void loop() {
  potValue = analogRead(potPin1);
  analogWrite(led9, potValue/4);
  Serial.println(potValue/4);      
  delay(10);                     
}
 
The below code runs in Processing and displays a selected RGB pattern on the screen. The brightness of color is dependant on the value collected from the pressure sensor:
 
import processing.serial.*;
Serial port;
float brightness = 0;
 
void setup()
{
  size(1600,900);
  port = new Serial(this, "COM3", 9600);
  port.bufferUntil('\n');  
}
 
void draw()
{
  background(0,0,brightness);
}
  
void serialEvent (Serial port)
{
  brightness = float(port.readStringUntil('\n'));
}
WP_20130226_002.jpg
0
Your rating: None
Drupal theme by Kiwi Themes.