/*

Toggles an LED after each detection of a button press, however this sketch
doesn't have any kind of debouncing mechanism or algorithim so expect some
weird results as it'll often register multiple presses as the button bounces.

*/
// The LED pin
int LED = 12;
// The button pin
int buttonPin = 8;
// initial state of button 0 for OFF, this variable tracks the state of the button
bool buttonState = 0;
// initial state of the LED 0 for OFF, this variable tracks the state of the LED
bool ledState = 0;

  

// the setup function runs once when you press reset or power the board
// Sets the LED to output and the buttonPin to INPUT where also setting up
// the serial monitor.
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
  Serial.println("Starting LED with push button.");
  Serial.println("Push button to toggle LED.");
}

// the loop function runs over and over again forever
void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == 1) {
        digitalWrite(LED,!ledState);
        ledState = !ledState;
  }
// I lied before, there is a tiny bit of a debounce with a delay between each checking of the
// button state. You can set the delay to 0 to see what happens with a bouncing button.
  delay(100);
}