/* Made by Jefferson Sandoval during the Embedded programming for the FabAcademy2021 * * This is just a simple testing code in C consisting of a button and a led, if the * button is pressed, the led is going do a quick blinking with the following sequence: * 1sec ON > 0.5secs OFF > 1sec ON > 0.5secs OFF > 1sec ON > turn OFF. * * This code was uploaded to a board with an Attiny1614 microcontroller. Documentation: * http://fabacademy.org/2021/labs/kamplintfort/students/jefferson-sandoval/assignments/week09/ */ #define F_CPU 3333333 //equals the frequency (20MHz) divided by 6 #include #include int main(void) { PORTA.DIR |= PIN3_bm; // Set LED as an output PORTA.DIR &= ~PIN2_bm; // Set button as an input PORTA.PIN2CTRL = PORT_PULLUPEN_bm; // Set PullUp resistors configuration while (true) { if (~PORTA.IN & PIN2_bm) // Check if button is pressed { // If button is pressed, do the blinking sequence for (int i=0; i<=3; i++){ _delay_ms(500); // Wait for half a sec PORTA.OUT |= PIN3_bm; // Turn led on _delay_ms(1000); // Wait for a sec PORTA.OUT &= ~PIN3_bm;} // Turn led off } else { PORTA.OUT = ~PIN3_bm;} //If button is not pressed, keep the LED off } return (0); }