Arduino的睡眠模式
from http://www.geek-workshop.com/thread-8715-1-1.html
睡眠模式Energy指令 中文直译 消耗电流
IdleIdle() 閒置 15mA
ADC Noise ReductionSleepADC() 类比数位转换器降低杂讯 6.5mA
Power-savePowerSave() 省电 1.62mA
StandbyStandby() 待机 1.62mA
Extended Standby 延长待机 0.84mA
Power-downPowerDown() 断电 0.36mA
- #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 to sleep...");
- energy.PowerDown();
- }
- }
留言
張貼留言