/* 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, the led * is going to blink 4 times depending on how long the button is pushed. * * 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 uint8_t counter = 0; while (true) { if(~PORTA.IN & PIN2_bm) // Check if button is pressed { while(~PORTA.IN & PIN2_bm) { // While button is being pressed... _delay_ms(100); // Add 1 to the counter every 0.1 secs counter++;} } if (counter > 0){ if(counter>=20) { for(uint8_t i = 0; i < 4 ; i++) {_delay_ms(1000); // Wait for a sec PORTA.OUT |= PIN3_bm; // Turn led on _delay_ms(1000); // Wait for a sec PORTA.OUT &= ~PIN3_bm;} // Turn led off } else{ for(uint8_t i = 0; i < 4 ; i++) {_delay_ms(250); // Wait for 0.25 secs PORTA.OUT |= PIN3_bm; // Turn led on _delay_ms(250); // Wait for 0.25 secs PORTA.OUT &= ~PIN3_bm;} // Turn led off } } else {PORTB.OUT &= ~PIN5_bm;} counter = 0; } return (0); }