lab3
* components used: arduino board, resistors, 3 potentiometers and 3 LEDs
* description:
3 LEDs are blinking in the same phase. pot #0 controls the brightness of all 3 LEDs, pot#1 controls the frequency of all 3 LEDs' blinking, pot#2 is changing the phase and brightness of blinking LEDs by turning on one LED with the brightness commanded by pot#2 , while other two LEDs are off. It starts from red and goes to green, blue, and then red ..
http://www.youtube.com/watch?v=5eY1zaTxmVQ
code:
int pot[] = {0, 1, 2}; // select the input pins for the potentiometer 1,2,3 (0,1,2)
int potVal [] = {0, 0, 0}; //initial values for pots
int color[] = {9,10,11};
/* color[0] = red, select pin 9 for this
color[1] = green, select pin 10 for this
color[2] = blue, select pin 11 for this */
void setup() {
for (int i = 0; i<=2; i++){
pinMode(color[i], OUTPUT); // declare the pin as an OUTPUT
}
}
void loop() {
for (int i = 0; i<=2; i++){
potVal[i]= map(analogRead(pot[i]), 1, 1023, 0, 255); //map digital -> analog
analogWrite(color[0], potVal[0]);
analogWrite(color[1], potVal[0]);
analogWrite(color[2], potVal[0]); // dim LEDs to value from pot0
delay(potVal[1]);
analogWrite(color[0], 0);
analogWrite(color[1], 0);
analogWrite(color[2], 0);
delay(potVal[1]); //blink LEDs with frequency set by pot1
analogWrite(color[i], potVal[2]);
delay(potVal[1]);
}
}
(1 vote)