Assignment: Sensing: Potentiometers
Collaborators:
I did a configuration where one pot controls the LED brightness and the other one controls the rate of blinking. I modified the code to create a LED train, which gives the impression that the lights follow each other. Look at the video for any clarifications.
http://www.cs.berkeley.edu/~anuj/Ledtrain.mp4
(It was captured from a cellphone, but enough to give an idea).
int led_pin1 = 9;
int led_pin2 = 10;
int led_pin3 = 11;
int val1 = 0;
int val2 = 0;
int input2 = 4;
int input1 = 5;
void setup() {
pinMode(led_pin1, OUTPUT);
pinMode(led_pin2, OUTPUT);
pinMode(led_pin3, OUTPUT);
}
void loop() {
val1 = analogRead(input1); // read the value from pot 1, between 0 - 1024, for dimming
val2 = analogRead(input2); // read the value from pot 2, between 0 - 1024, for blinking
analogWrite(led_pin1, val1/4); // dim LED to value from pot1
delay(val2/3); // stop the program for some time, meaning, LED is on for this time
analogWrite(led_pin2, val1/4); // dim LED to value from pot1
delay(val2/3); // stop the program for some time, meaning, LED is on for this time
analogWrite(led_pin3, val1/4); // dim LED to value from pot1
delay(val2/3); // stop the program for some time, meaning, LED is on for this time
analogWrite(led_pin1, 0); // dim LED to completely dark (zero)
delay(val2/3); // stop the program for some time, meaning, LED is on for this time
analogWrite(led_pin2, 0); // dim LED to completely dark (zero)
delay(val2/3); // stop the program for some time, meaning, LED is on for this time
analogWrite(led_pin3, 0); // dim LED to completely dark (zero)
}