After exploring two new analog sensors, namely photocells and Force Sensitive Resistors ("FSR"), I used them in combination with processing. It generate GUI object which can be controlled by input through sensors.
For homework, I used a FSR and created rectangle objects which blinks based on input through the FSR. To distribute force which the FSR detects, I sandwiched the FSR by two sponges. I think this structure can be used to detect pressure on everyday things such as coasters and entrance mat.
Components used:
1- Arduino Uno
1- Breadboard
1- 220ohms resistor
1- 10Kohms resistor
1- LED lights (blue)
14- Connecting wires
Processing
Arduino code:
int potPin = 0; // select the input pin for the potentiometer
int ledPin = 9; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
Serial.println(val);
analogWrite(ledPin, val/4); // analogWrite can be between 0-255
}
Processing code:
import processing.serial.*;
String portname = "/dev/tty.usbmodem1421";
Serial port;
int fsr = 0;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
void setup() {
size(500,500);
frameRate(10);
smooth();
background(40,40,40);
noStroke();
port = new Serial(this, portname, 9600);
}
void draw() {
background(40);
}
void keyPressed() {
if(key == ' ') {
background(40,40,40); // erase screen
}
else {
int x = int(random(0,width));
int y = int(random(0,height));
drawrect(x,y, 50);
}
}
// draw rect
void drawrect(int x, int y, int r) {
fill(100, 100, 255 );
rect(x,y,r,r);
}
// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c>15){
fsr = c;
}
// if (c != lf && c != cr) {
// buf += char(c);
// }
if (c == lf) {
//int val = int(buf)/100000;
//println("val="+val);
int x = int(random(0,width));
int y = int(random(0,height));
drawrect(x,y,fsr);
// buf = "";
// background(40,40,40); // erase screen
}
}
- Login to post comments