Question
Design a 5 bit binary LED up/down counter circuit that uses the UNO to count from 00000 to 11111 in 32 steps (with a pause of at least 0.25 seconds per step) and then counts back down to 00000. Use each of the five LED's (e.g. Red, Blue, Yellow, Green and Orange) to represent the one's, two's fours, eight's, and sixteen's of the output word. You should also connect a Tricolor LED to the UNO that glows violet during the upward count, then glows pink during the down count and finally goes dark when the last countdown reaches 00000. (You must determine what LED combinations of the Tri color diode will produce colors of violet and pink.)
Explanation / Answer
#include int count = 0; void setup() { OneSheeld.begin(); pinMode(3,OUTPUT); // declare LED pins as output pins pinMode(4,OUTPUT); pinMode(5,OUTPUT); pinMode(6,OUTPUT); pinMode(6,OUTPUT); } void loop() { if (GamePad.isOrangePressed()){ delay (10); // for debouncing if (GamePad.isOrangePressed()){ count ++ ; delay(200); if((count % 2) > 0) { digitalWrite(3, HIGH); } else { digitalWrite(3, LOW); } if((count % 4) > 1) { digitalWrite(4, HIGH); } else { digitalWrite(4, LOW); } if((count % 8) > 3) { digitalWrite(5, HIGH); } else { digitalWrite(5, LOW); } if((count % 16) > 7) { digitalWrite(6, HIGH); } else { digitalWrite(6, LOW); } LCD.begin(); LCD.print (count); OneSheeld.delay(250); } } if (GamePad.isRedPressed()){ delay (10); if (GamePad.isRedPressed()){ count -- ; delay(250); if((count % 2) > 0) { digitalWrite(3, HIGH); } else { digitalWrite(3, LOW); } if((count % 4) > 1) { digitalWrite(4, HIGH); } else { digitalWrite(4, LOW); } if((count % 8) > 3) { digitalWrite(5, HIGH); } else { digitalWrite(5, LOW); } if((count % 16) > 7) { digitalWrite(6, HIGH); } else { digitalWrite(6, LOW); } LCD.begin(); LCD.print (count); OneSheeld.delay(250); } } }