2018-12-24 16:28:33 [显示全部楼层]
4815浏览
查看: 4815|回复: 2

[进阶] 防治腰疼提醒器

[复制链接]
坐或站时间久了,就会腰酸背痛,与其事后治疗,不如提前预防。

这个设备用了一个时间模块,来精确的在每15分钟后用一个震动电机来提醒使用者注意休息。

防治腰疼提醒器图1
防治腰疼提醒器图2
[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]

20060606  高级技匠

发表于 2020-8-9 06:09:56

代码怎么插入的
回复

使用道具 举报

gada888  版主
 楼主|

发表于 2020-8-9 08:39:08

编辑器里找到</>,这个是代码插入
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail