Aidan Singh
Errors In the Code
- No semicolon after declaring a new variable (int buttonPin)
- Void Setup never set the second LED and button pins as inputs or outputs.
- The main void loop never used the function checkButton2()
https://www.tinkercad.com/things/h5NPnybvAzS
Code Explanation
- Function 1 will cycle through the LED’s whose switches are on, and blink them in order. This is due to the sequential if statements checking each switch, each containing a delay, so that once the leftmost switch is checked, it blinks the LED THEN checks the one to its right next.
- Function 2 only blinks the leftmost button that’s turned on. This is due to the use of else if statements, which only checks the remaining switches if the prior if statements are false.
- Function 3 blinks all LED’s whose switches are on. This is due to the use of sequential if statements and a delay that’s used after all the if statements turn on the corresponding LED’s.
Code Simplification