/* Made by Jefferson Sandoval during the Embedded programming for the FabAcademy2021 * * This is just a simple testing code in Arduino consisting of a button and a led. * If led is On, pressing the button will turn it off. * If led is Off, pressing the button will turn it on. * * This code was uploaded to a board with an Attiny1614 microcontroller. Documentation: * http://fabacademy.org/2021/labs/kamplintfort/students/jefferson-sandoval/assignments/week09/ */ const int button = 9; // Set number of the button pin const int led = 10; // Set number of the LED pin byte buttonState = 0; // Variable for button status byte lastButtonState = 0; // previous state of the button int PressCounter = 0; // Button press counter void setup() { pinMode(led, OUTPUT); // Set LED as an output pinMode(button, INPUT_PULLUP); // Set button as an input with PullUp resistors configuration } void loop() { buttonState = digitalRead(button); // Read state of the button value if (buttonState != lastButtonState) { // Compare buttonState to lastButtonState if (buttonState == HIGH) { // If the current state is HIGH, button was pushed PressCounter++;} delay(25);} lastButtonState = buttonState; // Save the current state as lastButtonState, for next comparison if (PressCounter % 2 == 0) { digitalWrite(led, HIGH); // If modulo = 0, turns on the LED. } else { digitalWrite(led, LOW); //If modulo != 0, turns off the LED. } }