chris许 发表于 2018-10-23 16:48:30

久坐提醒器


代码
#include <SoftI2CMaster.h>
#include <LiquidCrystal_SoftI2C.h>
#include <MsTimer2.h>

volatile float distance;

float checkdistance_8_7() {
digitalWrite(8, LOW);
delayMicroseconds(2);
digitalWrite(8, HIGH);
delayMicroseconds(10);
digitalWrite(8, LOW);
float distance = pulseIn(7, HIGH) / 58.00;
delay(10);
return distance;
}

LiquidCrystal_SoftI2C mylcd(0x20,16,2,A5,A4);
void msTimer2_func() {
mylcd.clear();
distance = checkdistance_8_7();
delay(10);
if (distance < 51) {
    tone(0,131);
    delay(10);
    mylcd.setCursor(1-1, 1-1);
    mylcd.print("您已久坐,");
    mylcd.setCursor(1-1, 0-1);
    mylcd.print("该运动一下啦!");
    delay(300);

}
}

void setup(){
pinMode(8, OUTPUT);
pinMode(7, INPUT);
distance = checkdistance_8_7();
mylcd.init();
mylcd.backlight();
mylcd.display();
pinMode(0, OUTPUT);
}

void loop(){
if (digitalRead(7) == HIGH) {
    digitalWrite(8,HIGH);
    MsTimer2::set(1800000, msTimer2_func);
    MsTimer2::start();

} else {
    digitalWrite(8,LOW);

}
for (int time = 1; time <= 10; time = time + (1)) {
    mylcd.clear();
    distance = checkdistance_8_7();
    delay(10);
    if (distance < 51) {
      tone(0,131);
      delay(10);
      mylcd.setCursor(1-1, 1-1);
      mylcd.print("您已久坐,");
      mylcd.setCursor(1-1, 0-1);
      mylcd.print("该运动一下啦!");
      delay(300);

    }
}

}






chris许 发表于 2018-10-23 16:49:14

请大神帮我看看 代码是否有什么不对的地方希望能得到帮助谢谢:))

DFBJOseAZnM 发表于 2018-10-24 10:54:40

实现不了?

DFBJOseAZnM 发表于 2018-10-24 10:54:52

是吗?

gada888 发表于 2018-11-27 21:27:32

DFBJ1tpvsP4 发表于 2019-3-17 14:55:59

请问您最后解决了吗?
页: [1]
查看完整版本: 久坐提醒器