我是arduino的新手。我需要的是让他在特定的时间做某事,然后去睡觉,这样它就不会过度工作。
具体任务是:我希望他开始喂养我的黄金鱼的机制,所以在休假时间arduino应该工作10天或更长时间(这是睡眠模式的原因)。
在研究这个问题时,我想出了时间中断,但我认为这不是最佳解决方案,因为我希望他在特定时间做某事,而不是打断他的任务。
感谢您提供任何帮助:)
答案 0 :(得分:0)
我喜欢@Josh使用时钟重置设备的解决方案,但here's another idea如果你的鱼在毫秒没有喂食的话就会死亡。
答案 1 :(得分:0)
使用millis()方法。它将在50天后重置,但我认为你不会长途旅行......
unsigned long hours4nextFeeding = 8;
unsigned long lastTime = millis();
void loop() {
if(millis() > (lastTime + (hours4nextFeeding*3600*1000))) {
feedTheFish();
lastTime = millis();
}
delay(60000);
}
此外,你可以使用光传感器(supercheaper),并在太阳升起时每天喂鱼一次
我刚刚编写的代码未经测试,但您应该明白这一点。
答案 2 :(得分:0)
我读过标准的Arduino电路板并没有节省那么多功率,因为功率调节器和USB端口(如果有的话)会消耗大量功率。但是考虑到你使用外部时钟来触发设备唤醒,你可以使用一个简单的arduino库Enerlib。
Engblaze有一个nice article关于如何自己做,但如果你是arduino的新手,你可能不想跳进AVR库。
答案 3 :(得分:0)
你可以尝试一些简单的事情,比如每30秒开始一次持续20秒的事件:
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
void setup () {
Serial.begin(57600);
#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
rtc.begin();
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
}
}
boolean pumpOn = false;
void loop () {
DateTime now = rtc.now();
if(now.second()%30==0){ pumpOn=true;}
if(now.second()%50==0){ pumpOn=false;}
if(pumpOn)
Serial.println("on");
}
}