それは確かに非常に深い眠りに入ることを救うために魅力的です
電源は、しかし、あなたはまだ目を覚ます必要がありますどのような周辺機器
ウェイクアップソースとして使用します。 16ビットタイマを使用する場合は、
SLEEP_MODE_IDLE
以外の選択肢。
しかしそれはそれほど悪くないかもしれません。 IDLEモードでは、
あなたが使用していない周辺機器をクロックする(したがってスリープさせる)。または多分
すべてを寝てから、必要なものを少しだけ目を覚ましてください。この
は、 power _ * _ disable()
および power _ * _ enable()
の機能の。
以下の編集コードでは、Timer 1を除くすべての周辺機器は無効になっています
CPUはスリープします。 USARTは、必要な時間だけ有効になります
そのメッセージを送る:
#include
#include
#include
#include
const uint16_t PERIOD = 2150; //34.4 ms
void setup()
{
//Disable all but the needed peripherals.
power_all_disable();
power_timer1_enable();
//This is for debug pulses.
pinMode(22, OUTPUT);
//Configure Timer 1 to wake us up every 34.4 ms.
TCCR1A = 0; //undo the timer config done...
TCCR1B = 0; //...by the Arduino core library
TCNT1 = 0; //reset the timer
OCR1A = PERIOD - 1; //set the period
TIMSK1 = _BV(OCIE1A); //enable TIMERx_COMPA interrupt
TCCR1B = _BV(WGM12) //CTC mode, TOP = OCR1A
| _BV(CS12); //...and set the prescaler /256
Serial.begin(9600);
}
ISR(TIMER1_COMPA_vect)
{
//Send a debug pulse.
digitalWrite(22, HIGH);
_delay_ms(2);
digitalWrite(22, LOW);
}
void loop()
{
//Enable the USART only while needed.
power_usart0_enable();
Serial.println("Program is on");
Serial.flush();
power_usart0_disable();
//And go to sleep in IDLE mode.
sleep_mode();
}
ISRはシリアルポートには印刷されません。
スコープで監視するデバッグパルスを送信します。これはから削除する必要があります
生産コード。この遅延はavr-libc関数を使って達成されます
標準のArduino delay()
が機能しないため、 _delay_ms()
無効になっているタイマ0に依存します。