4815| 2
|
[进阶] 防治腰疼提醒器 |
坐或站时间久了,就会腰酸背痛,与其事后治疗,不如提前预防。 这个设备用了一个时间模块,来精确的在每15分钟后用一个震动电机来提醒使用者注意休息。 [mw_shl_code=applescript,true]/****made by gada888****/ #include <Wire.h> #include "RTClib.h" RTC_DS1307 rtc; unsigned long timer; unsigned long pumpTimeOn = 60000; //1 min in milliseconds unsigned long pumpTimeOff = 900000; //15 min in milliseconds boolean pumpState = 1; int pumpPin = 7; void setup () { Serial.begin(57600); #ifdef AVR Wire.begin(); #else Wire1.begin(); #endif rtc.begin(); if (! rtc.isrunning()) { Serial.println("RTC is NOT running!"); rtc.adjust(DateTime(2014,12,16,12,52,0)); } pinMode(pumpPin, OUTPUT); timer = millis(); } void loop () { if(pumpState == 1){ digitalWrite(pumpPin, HIGH); unsigned long currentMillis = millis(); if(currentMillis >= (timer + pumpTimeOn)){ pumpState = 0; Serial.println("the pump is now off at this time:"); printCurrentTime(); timer = millis(); } } if(pumpState == 0){ digitalWrite(pumpPin, LOW); unsigned long currentMillis = millis(); if(currentMillis >= (timer + pumpTimeOff)){ pumpState = 1; Serial.println("the pump is now on at this time:"); printCurrentTime(); timer = millis(); } } //delay(3000); } void printCurrentTime(){ DateTime now = rtc.now(); Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.day(), DEC); Serial.print(' '); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(); Serial.print(" since midnight 1/1/1970 = "); Serial.print(now.unixtime()); Serial.print("s = "); Serial.print(now.unixtime() / 86400L); Serial.println("d"); // calculate a date which is 7 days and 30 seconds into the future DateTime future (now.unixtime() + 7 * 86400L + 30); Serial.print(" now "); Serial.print(future.year(), DEC); Serial.print('/'); Serial.print(future.month(), DEC); Serial.print('/'); Serial.print(future.day(), DEC); Serial.print(' '); Serial.print(future.hour(), DEC); Serial.print(':'); Serial.print(future.minute(), DEC); Serial.print(':'); Serial.print(future.second(), DEC); Serial.println(); Serial.println(); }[/mw_shl_code] |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed