More More More!
The second part of my PComp Arduino assignment was to “get creative” by building on the blinking LED exercise. I didn’t want to come up with a new switch, because everyone seems to be doing that. I have experience with programming in C, and I like LEDs, so I decided to up the ante by adding more LEDs (five instead of two) and more code. The blink pattern is supposed to be reminiscent of old timey jukeboxes and cinema marquees.
Here’s the video:
And here’s the code:
[code lang="c"] int pinCount = 3; //tells what pin info is sent to, starts at pin 3 void setup(){ pinMode(2, INPUT); //switch at pin 2 pinMode(3, OUTPUT); //red LED at pin 3 pinMode(4, OUTPUT); //green LED at pin 4 pinMode(5, OUTPUT); //red LED at pin 5 pinMode(6, OUTPUT); //green LED at pin 6 pinMode(7,OUTPUT); //blue LED at pin 7 } void loop(){ if(digitalRead(2)==HIGH) //switch closed { while (pinCount < 7) //all LEDs light up in ascending pin order { digitalWrite(pinCount, HIGH); delay(500); digitalWrite(pinCount, LOW); delay(500); pinCount++; } if (pinCount == 7) { for (int i = 0; i =3; pinCount--) //all LEDs light up in reverse order { digitalWrite(pinCount, HIGH); delay(1000); } } } else //switch open { digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); } } [/code]