/* * Button pressed LED ON * A C program that activates the LED connected * to the PA5 pin when pressing the button * connected to the PA4 pin of the MidTiny board (Base ATtiny1614). * * Author: Harley Lara * Create: 03 May 2021 * License: (CC BY-SA 4.0) Attribution-ShareAlike 4.0 International * * This work may be reproduced, modified, distributed, * performed, and displayed for any purpose, but must * acknowledge this project. Copyright is retained and * must be preserved. The work is provided as is; no * warranty is provided, and users accept all liability. */ #define F_CPU 3333333 #include #include #define LED PIN5_bm // Define LED pin #define BUTTON PIN4_bm // Define BUTTON pin int main() { PORTA.DIR |= LED; // Define the LED port as output PORTA.OUT &= ~LED; // Set the initial state of the LED OFF PORTA.DIR &= ~BUTTON; // Define the button port as input PORTA.PIN4CTRL = 0; // Don't use the internal pullup resistor while (true) { _delay_ms(10); // Wait if (PORTA.IN & BUTTON) // If the button is pressed { PORTA.OUT ^= LED; // LED toggle ON/OFF } else { PORTA.OUT &= ~LED; // If the button is not pressed set LED OFF } } return 0; }