Here is my design for the "fading LED" assignment. The goal of this design is to make a Chinese to-go box light up whenever you use chopsticks correctly. This design aims to teach kids/people using chopsticks. The only way to light up the to-go box (which says "Yummy") is to connect the tips of the two chopsticks. I am using three LEDs in red, green and blue. The three LEDs fade in different speed, so they cast shadows of the "Yummy" in a dynamic way.
Yury brought up in class that one might "cheat" when using it. Some ways to prevent cheatings are: 1. tie the ends of the chopsticks 2. examine the proximity of the tips 3. have an adult watching. But I think this is a learning tool that's for anyone who really wants to learn, cheating might not be the biggest problem. Maybe I can think about using the single hand as a conductor, though.
One thing that I''m thinking about is that, how to make the chopsticks "free to move"? It means not having wires connect chopsticks to the arduino board. Using wireless is one option, but the smallest wireless receiver that I can find at NYU store is still a little too big.
Working on it. More to come soon..
Here is the code:
// Shan Liu
// Assignment: to design something that uses fading LEDs.
// Project name: Yummy: how to use chopsticks.
// Physical Computing, prof. Yury Gittman
// Oct. 1st, 2010
// Assign three pins to control three LEDs.
#define LED 9
#define LEDd 3
#define LEDc 5
// Assign one pin to control one button.
#define Button 7
// setting up integers that can help determine the human interaction state.
int val = 0;
int old_val = 0;
int state = 0; //boolean 0 = LED off; 1 = LED on.
// set the initial brightness of the LEDs.
int brightness1 = 128;
int brightness2 = 128;
int brightness3 = 128;// "brightness" stores the brightness value
// I don't quite understand what "unsigned long" does.
unsigned long startTime = 0;
void setup(){
// pins that control LEDs are outputs while the one that controls button is input.
pinMode(LED, OUTPUT);
pinMode(LEDc, OUTPUT);
pinMode(LEDd, OUTPUT);
pinMode(Button, INPUT);
}
void loop(){
val = digitalRead(Button); //digitalRead detects if button is pushed.
if ((val == HIGH)&&(old_val == LOW)){
// HIGH means pressed or "1". and LOW means not pressed or "0".
state = 1- state;
startTime = millis(); // startTime records how many millisecons have passed since the board was reset.
delay(10);
// "delay" prevents the LEDs flash like crazy. It slows the process down.
// Because the process is kind of time-based. It counts millisecons in order to proceed to the next step.
}
if ((val == HIGH) && (old_val == HIGH)) { // check if the button is being held down.
if (state == 1 && (millis() - startTime)>500){ // if button was pressed long enough.
// Three LEDs are taking brightness at different value, which means they fade at different speeds.
brightness1 = brightness1+1;
brightness2 = brightness2+2;
brightness3 = brightness3+3;
delay(20);
// If the brightness value exceeds 255(the brightest a LED can be), it goes back to 0(LED turns off).
if (brightness1 > 255) {
brightness1 = 0;
}
if (brightness2 > 255) {
brightness2 = 0;
}
if (brightness3 > 255) {
brightness3 = 0;
}
}
}
old_val = val;
// because Arduino is running through this loop over and over again, the val constantly becomes old_val
// after each loop.
// this means two things: 1. if LED was off(old_val==LOW), and button is pressed(val==HIGH), then turn LED on.
// 2. if LED was on(old_val==HIGH, because old_val=val), and buttons is pressed(val=HIGH), then turn
// from here on it deals with LED (visual stuff).
if (state == 1){
analogWrite(LEDd, brightness1);
analogWrite(LED, brightness2);
analogWrite(LEDc, brightness3);
}
else{
analogWrite (LED, 0);
analogWrite (LEDd, 0);
analogWrite (LEDc, 0);
}
}
Comments
You can follow this conversation by subscribing to the comment feed for this post.