/* 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 * the button is pressed, the led is going fade in and fade out one time. * * 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 = 1; // Variable for button status 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 == LOW) // Check if button is pressed { // If button is pressed, Turn on LED delay(500); // fade in from min to max in an increments of 5 for (int i=0; i<=255; i+=5){ analogWrite(led, i); delay(50);} // fade out from max to min in a decrement of 5 for (int i=255; i>=0; i-=5){ analogWrite(led, i); delay(50);} } else { digitalWrite(led, LOW);} // If button is not pressed, keep the LED off }