Posts

Showing posts from January, 2020

Interrupts

          Interrupts example for Arduino Uno #include<avr/sleep.h> #include <avr/power.h> volatile int f_wdt=1; int flag=false; void setup() {   // put your setup code here, to run once:   pinMode(LED_BUILTIN,OUTPUT);   digitalWrite(LED_BUILTIN,LOW);   attachInterrupt(digitalPinToInterrupt(2), blink, CHANGE);   Serial.begin(9600); //LowPower.sleep(500000); watch(); } void enter_sleep() {   set_sleep_mode(SLEEP_MODE_PWR_DOWN);   sleep_enable();   sleep_mode();   sleep_disable();   sleep_enable();   power_all_enable();    } ISR(WDT_vect){   if(f_wdt==0)      f_wdt=1;    } void watch() {   MCUSR&=~(1<<WDRF);   WDTCSR |= (1<<WDCE) | (1<<WDE);   WDTCSR  = (1<<WDP3) | (0<<WDP2) | (0<<WDP1) | (1<<WDP0);   WDTCSR |= _BV(WDIE); } void blink() {   f...