Idea:
In high school, I remember having O-level exams with 40 Multiple Choice Questions and each MCQ had 4 options to choose from. In class, everyone was supposed to work on their paper for a set amount of time after which the teacher would one by one say the correct answer out loud. The problem started when in a class of 30 energetic students the teacher’s voice was reduced to a mere muffle. The other issue was the confusion between the option ‘B’ and ‘D’ which sounds so similar that a clarification of ‘B for Ball’ and ‘D for Dog’ was always followed. This gave me the idea to make a 4 LED structure that can be used to communicate the correct answer for each MCQ one by one. The teacher can click the corresponding number of times and display the correct option and then follow it with an explanation of the respective MCQ.
Code:
int buttonPin = 7; int LED1 = 13; int LED2 = 12; int LED3 = 11; int LED4 = 10; int initial = 0; int lastState = 0; int buttonState = LOW; void setup() { // put your setup code here, to run once: pinMode(13, OUTPUT); pinMode(12, OUTPUT); pinMode(11, OUTPUT); pinMode(10, OUTPUT); pinMode(7, INPUT); } void loop() { // put your main code here, to run repeatedly: buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { delay(500); buttonState = digitalRead(buttonPin); if (buttonState == LOW) //when pressed move to next led { initial = lastState + 1; } } else { delay(100); } if(initial == 1) //first time blue is lit up { digitalWrite (13, HIGH); digitalWrite (12, LOW); digitalWrite (11, LOW); digitalWrite (10, LOW); lastState = 1; } else if(initial == 2) //second time yellow is lit up { digitalWrite (13, LOW); digitalWrite (12, HIGH); digitalWrite (11, LOW); digitalWrite (10, LOW); lastState = 2; } else if (initial == 3) //third time green is lit up { digitalWrite (13, LOW); digitalWrite (12, LOW); digitalWrite (11, HIGH); digitalWrite (10, LOW); lastState = 3; } else if (initial == 4) //fourth time red is lit up { digitalWrite (13, LOW); digitalWrite (12, LOW); digitalWrite (11, LOW); digitalWrite (10, HIGH); lastState = 4; } else //all LEDs off { digitalWrite (13, LOW); digitalWrite (12, LOW); digitalWrite (11, LOW); digitalWrite (10, LOW); lastState = 0; } }