How to wake up arduino by conditions


hey guys!
i'm trying wake arduino information ds1307. examples found using attachinterrupt. don't want to  wake pins situation (change/high/low/high-to-low...). there way wake condition?
here's example use !
code: [select]
#include <enerlib.h>

energy energy;             // 宣告"energy"程式物件

const byte swpin = 2;      // 開關腳位
const byte ledpin = 13;    // led腳位
byte times = 0;            // 記錄執行次數
volatile byte state = 0;   // 暫存執行狀態

void wakeisr() {
   if (energy.wassleeping()) {
    state = 1;
  } else {
    state = 2;
  }
}

void setup() {
  serial.begin(9600);
 
  pinmode(ledpin, output);
  pinmode(swpin, input);
  digitalwrite(swpin, high);
 
  attachinterrupt(0, wakeisr, change);  // 附加中斷服務常式
 
  serial.println("running...");
}

void loop()
{
  if (state == 1) {
    serial.println("was sleeping...");
  } else if (state == 2) {
    serial.println("was awake...");
  }
  state = 0;
 
  digitalwrite(ledpin, !digitalread(ledpin));
  delay(500);
  times ++;
  serial.println(times);

  if (times > 5) {
    times = 0;
    serial.println("go sleep...");
    energy.powerdown();
  }
}

the ways wake sleep external interrupt (pin changing state, either int1/int0 or pcints), or using watchdog timer wake periodically (note wdt doesn't keep accurate time either)

the 1307 doesn't have way drive pin high/low in response time-related event. microcontroller cannot communicate on i2c while sleeping. think you'll need use wdt periodically wake, , interrogate ds1307 determine if needs done.

i think there exist rtc chips can drive pin high or low @ specified time - not ds1307


Arduino Forum > Using Arduino > Microcontrollers > How to wake up arduino by conditions


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor