/* Button Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2. The circuit: * LED attached from pin 13 to ground * pushbutton attached to pin 2 from +5V * 10K resistor attached to pin 2 from ground ____. .__ .__ .__ | |__ __ _____ ______ ____ | |__ _____ | | | | ____ ____ ____ ____ | | | \/ \\____ \ _/ ___\| | \\__ \ | | | | _/ __ \ / \ / ___\_/ __ \ /\__| | | / Y Y \ |_> > \ \___| Y \/ __ \| |_| |_\ ___/| | \/ /_/ > ___/ \________|____/|__|_| / __/ \___ >___| (____ /____/____/\___ >___| /\___ / \___ > \/|__| \/ \/ \/ \/ \//_____/ \/ */ const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin int buttonState = 0; // variable for reading the pushbutton status int score = 0; // variable for scorekeeping void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT); Serial.begin(9600); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // Button press loop if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); score = score + 1; Serial.println(score); delay(300); buttonState = LOW; } else { // turn LED off: digitalWrite(ledPin, LOW); } // Reaching highscore loop if (score == 25){ Serial.println("HURRAH You reached the highscore!"); score = 0; } }