#include #include #define DEBUG 0 // rx is not being used, so that's a dummy number. NewSoftSerial XBSerial = NewSoftSerial(5, 4); int CTSpin = 7; int XBpin = 6; static int CTS=0; // value of XBee CTS digital pin static byte wdt_count = 0; // watchdog timer counter static unsigned long tBusyPrev=0; // busy time of each transmission volatile boolean wdt_expired=0; // 1 when watchdog timer expired. // Interrupt Service Routine that will be executed when the Watchdog Timer expires. ISR(WDT_vect) { wdt_expired=1; } void setup_watchdog(int ii) { // // parameter: // 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms // 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec // byte bb; int ww; if (ii > 9 ) ii=9; bb=ii & 7; if (ii > 7) bb|= (1<<5); bb|= (1<= 4) { // since watchdog expired, there's no motion... Send(0); } } else { // Motion! Send(1); // Go to sleep WITHOUT activating IRQ, // wake up after some time and resume operation *with*. // This is to avoid multiple motion notifications // being sent in a very short time, caused by // the PIR output jumping high and low all the time, // call it debouncing :-) setup_watchdog(9); Sleep.powerDown(); // after waking up again, // enter powerdown with IRQ again. } }