Desription
Through one potentiomenter and FSRs, I control the brightness and blinking of 2LEDs. I also find material, a soft plastic model, to control perssure for ESRs effectively. On processing, I tried to control digital ball's reflection.
Components
1LED, a ping-pong ball as a diffuser, a red soft plastic heart, FSRs, 1 petentiometer, 9wires, Arbuino Board, Bread Board
Arduino Codes
int pot1Pin = 0; // select the input pin for the FSRs, Brightness
int pot2Pin = 1; // select the input pin for the potentiometer1, Blinking
int pot1Val = 0; // variable to store the value coming from pot 1
int pot2Val = 0; // variable to store the value coming from pot 2
int redPin = 9; // the pin for the red LED
int greenPin = 10; // the pin for the green LED
void setup() {
pinMode(redPin, OUTPUT); // declare the led1Pin as an OUTPUT
pinMode(greenPin, OUTPUT); // declare the led2Pin as an OUTPUT
}
void loop() {
pot1Val = analogRead(pot1Pin); // read the value from pot 1, between 0 - 1024, for dimming
pot2Val = analogRead(pot2Pin); // read the value from pot 2, between 0 - 1024, for blinking
analogWrite(redPin, pot1Val/4); // dim LED to value from pot1
analogWrite(greenPin, pot1Val/4);
delay(pot2Val); // stop the program for some time, meaning, LED is on for this time
analogWrite(redPin, 0); // dim LED to completely dark (zero)
analogWrite(greenPin, 0);
delay(pot2Val); // stop the program for some time, meaning, LED is OFF for this time
}
Processing
import processing.serial.*;
String portname = "COM4";
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
int fsr = 0;
void setup() {
size(300, 300, P3D);
noStroke();
colorMode(RGB, 1);
fill(0.4);
port = new Serial(this, portname, 9600);
}
void draw() {
background(0);
translate(width / 2, height / 2);
// Set the specular color of lights that follow
lightSpecular(3, 3, 3);
directionalLight(0.8, 0.8, 0.8, 0, 0, -1);
float s = fsr / float(width);
specular(s, s, s);
sphere(50);
}
// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
fsr = int(buf);
println("fsr="+fsr);
buf = "";
}
}
Video
http://www.youtube.com/v/-V8AQx_d-40