Create a gist now

Instantly share code, notes, and snippets.

Murr
// From http://www.instructables.com/id/Vibrating-Timekeeper
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>
int countr;
ISR(WDT_vect) {
countr++;
}
void setup(){
pinMode(0, OUTPUT);
setup_watchdog(6);
}
void loop()
{
ADCSRA &= ~(1<<ADEN);
sleep_mode();
if (countr>300){
countr=0;
digitalWrite(0,HIGH);
delay(1000);
digitalWrite(0,LOW);
}
}
void setup_watchdog(int timerPrescaler) {
if (timerPrescaler > 9 ) timerPrescaler = 9; //Limit incoming amount to legal settings
byte bb = timerPrescaler & 7;
if (timerPrescaler > 7) bb |= (1<<5); //Set the special 5th bit if necessary
//This order of commands is important and cannot be combined
MCUSR &= ~(1<<WDRF); //Clear the watch dog reset
WDTCR |= (1<<WDCE) | (1<<WDE); //Set WD_change enable, set WD enable
WDTCR = bb; //Set new watchdog timeout value
WDTCR |= _BV(WDIE); //Set the interrupt enable, this will keep unit from resetting after each int
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment