Devices & Components
Arduino Uno Rev3
USB-A to Mini-USB Cable
Pushbutton switch 12mm
Breadboard (generic)
Jumper wires (generic)
LED (generic)
Resistor 220 ohm
Resistor 10k ohm
Software & Tools
Arduino IDE
Project description
Code
Simple Reflex Game
arduino
Copy and paste the code below into your Arduino Editor
1int ledPin = 13; 2int sensorPin1 = 2; 3int long ranDelay = 0; 4int sensorValue = 0; 5float realTime; 6 7void setup() 8{ 9 Serial.begin(9600); 10 pinMode(ledPin, OUTPUT); 11 pinMode(sensorPin1, INPUT); 12} 13 14void loop(){ 15 Serial.println(""); 16 Serial.println(""); 17 Serial.println(""); 18 Serial.println("Push the button to start game"); 19 20 while (digitalRead(sensorPin1)== 0) { 21 } 22 Serial.println(""); 23 Serial.println(""); 24 Serial.println(""); 25 Serial.println("Get Ready!"); 26 delay(1000); 27 Serial.println("Get Set!"); 28 delay(1000); 29 ranDelay = random(5000); 30 delay(ranDelay); 31 Serial.println("Go!"); 32 33 realTime = millis(); 34 digitalWrite(ledPin, HIGH); 35 36 37 while (digitalRead(sensorPin1)== 0) { 38 39 } 40 digitalWrite(ledPin, LOW); 41 Serial.println("Your time was"); 42 realTime = millis()-realTime; 43 Serial.print(realTime/1000,2); 44 Serial.println(" seconds"); 45 delay(2000); 46} 47 48
Simple Reflex Game
arduino
Copy and paste the code below into your Arduino Editor
1int ledPin = 13; 2int sensorPin1 = 2; 3int long ranDelay = 0; 4int sensorValue = 0; 5float realTime; 6 7void setup() 8{ 9 Serial.begin(9600); 10 pinMode(ledPin, OUTPUT); 11 pinMode(sensorPin1, INPUT); 12} 13 14void loop(){ 15 Serial.println(""); 16 Serial.println(""); 17 Serial.println(""); 18 Serial.println("Push the button to start game"); 19 20 while (digitalRead(sensorPin1)== 0) { 21 } 22 Serial.println(""); 23 Serial.println(""); 24 Serial.println(""); 25 Serial.println("Get Ready!"); 26 delay(1000); 27 Serial.println("Get Set!"); 28 delay(1000); 29 ranDelay = random(5000); 30 delay(ranDelay); 31 Serial.println("Go!"); 32 33 realTime = millis(); 34 digitalWrite(ledPin, HIGH); 35 36 37 while (digitalRead(sensorPin1)== 0) { 38 39 } 40 digitalWrite(ledPin, LOW); 41 Serial.println("Your time was"); 42 realTime = millis()-realTime; 43 Serial.print(realTime/1000,2); 44 Serial.println(" seconds"); 45 delay(2000); 46} 47 48
Downloadable files
Circuit Diagram
Circuit Diagram

Comments
Only logged in users can leave comments