我在网上看到一个关于mega 2560休眠模式的帖子,但是里面只能睡眠8s,我也不太清楚是否能省电,里面用到的是一个外国人写的库,叫lowpower,我想要休眠30分钟以上该怎么办,有没有- #include "LowPower.h"
- const byte swPin = 2; // 開關腳位
- const byte ledPin = 13; // LED腳位
- byte times = 0; // 記錄執行次數
- volatile byte state = 0; // 暫存執行狀態
- void wakeISR() {
- state = 1;
- }
- void setup() {
- Serial.begin(9600);
-
- pinMode(ledPin, OUTPUT);
- pinMode(swPin, INPUT);
- digitalWrite(swPin, HIGH);
-
- // 附加中斷服務常式,當中斷0為低電位時,喚醒處理器。
- attachInterrupt(0, wakeISR, LOW);
- }
- void loop()
- {
- if (state) {
- Serial.println("Running...");
- state = 0;
- }
-
- // 閃爍5次LED之後進入睡眠
- digitalWrite(ledPin, !digitalRead(ledPin));
- delay(500);
- times ++;
- Serial.println(times);
- if (times > 5) {
- times = 0;
-
- // 用最低耗電模式進入睡眠
- // SLEEP_FOREVER代表停用「看門狗」,約可節省 4µA 電流消耗。
- // 選擇性的ADC_OFF,代表關閉「類比數位轉換器(ADC)」
- // 選擇性的BOD_OFF,代表關閉「電源供應電壓準位偵測器(BOD)」,約可節約 17µA。
- LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
- }
- }
复制代码 相关的其他库。下面是代码 |