-The pushbutton and resistors are only needed. No LEDs.
-This is the Serial Monitor:
-The variable buttonPresses holds the number of times you press the button and is increased every time the pushbutton changes state (if(val != buttonState)) and it is pressed (val == LOW)
Countdown Device:
-The circuit is the same but I modified the code drastically:
-I added an if-statement that checks if buttonPresses = 0 to print "EXPLODE!" only, else it will print the countdown message. I also added another condition in the first if-statement, to make sure we do not go below 0. Once buttonPresses reaches zero, the loop() function stops executing (it will just go to the end of the function.)
-PS: I got bored of the Arduino IDE since it does not provide an autocomplete function (or IntelliSense feature), so I downloaded and installed PlatformIO and an Arduino Package that lets you Build the project and Upload it to a physical Arduino UNO. PlatformIO even has its own Serial Monitor.Design Challenge 1:
-I created a new bool (boolean) variable lightMode that stores the state of the bike light (false = OFF). I also made an array of ints for the LEDs pin 12-8.
-If the button was pressed, the value of lightMode toggles and if it is TRUE, then I turn on all LEDs, else turn them off. The effects of the digitalWrite() function will stay the same, even if not touching the pushbutton.
Brooklyn debounce:
-The circuit design is the same. But the code is different. They double-check the input value from the switch after a 10 ms delay before doing anything else.
-The code for the "blinky" lights only makes the LEDs blink once. Apparently, this is not what it is supposed to do (this was hard to understand by the way.) What the code should do is change the value of lightMode after double-checking the input read from the switch (it is in the original code, so that part is fine), however, you want the "blinky" functionality to run outside the double-check, so even if you did not touch the pushbutton, it will do whatever it was doing.
Blinky Bike Lights:
-This is my code:
Design Challenge 3:
-I think lightMode++ (incrementing the mode) should be asynchronous, so every time the user presses the button, it changes the mode to the next one. So, what I did was add a "jump" to go back to the beginning of the loop() function at the end of each function that had a delay() (the call to loop() is after the delay).
No comments:
Post a Comment