// ========================================================== // Push button using the built in 20k pullup resistor // Debounce is just a simple 1/2 second delay // ---------------------------------------------------------- // For more information about pins, pull up resistors, etc. // https://www.arduino.cc/en/Tutorial/Foundations/DigitalPins // ========================================================== // ---------------------------------------------------------- // ---- global // ---------------------------------------------------------- const int baudrate = 19200; const int buttonPin = 2; const int ledPin = 7; bool ledState = false; // ---------------------------------------------------------- // ---- setup // ---------------------------------------------------------- void setup() { pinMode(buttonPin,INPUT_PULLUP); pinMode(ledPin,OUTPUT); digitalWrite(ledPin,LOW); Serial.begin(baudrate); } // ---------------------------------------------------------- // ---- loop // ---------------------------------------------------------- void loop() { if(digitalRead(buttonPin) == LOW) { Serial.println("LOW"); Serial.flush(); if (ledState) { digitalWrite(ledPin,LOW); ledState = false; } else { digitalWrite(ledPin,HIGH); ledState = true; } delay(500); } }