4259| 5
|
久坐提醒器 |
代码 #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); } } } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed