4070| 8
|
[求助] 用心率控制夜灯 |
gada888 发表于 2019-10-31 11:56 #define heartratePin A1 //定义心率传感器信号的引脚 #include "DFRobot_Heartrate.h" //库文件 int Relay=3; //选一个I/O DFRobot_Heartrate heartrate(DIGITAL_MODE); //传感器信号选择 void setup() { Serial.begin(115200); //串口波特率 pinMode(Relay,OUTPUT); //定义输出 } void loop() { uint8_t rateValue; heartrate.getValue(heartratePin); rateValue = heartrate.getRate(); //读心率数据 if(rateValue){ Serial.println(rateValue); //串口显示 } delay(20); if(rateValue>50){ digitalWrite (Relay,HIGH); //大于50输出高电平 } else { digitalWrite (Relay,LOW); //小于50输出低电平 } } 版主大神,能不能帮我看看哪里有问题啊 |
我没有这个模块,没法测试。只是加了delay。你试试 [mw_shl_code=applescript,false]#define heartratePin A1 //定义心率传感器信号的引脚 #include "DFRobot_Heartrate.h" //库文件 int Relay=3; //选一个I/O DFRobot_Heartrate heartrate(DIGITAL_MODE); //传感器信号选择 void setup() { Serial.begin(115200); //串口波特率 pinMode(Relay,OUTPUT); //定义输出 } void loop() { uint8_t rateValue; heartrate.getValue(heartratePin); rateValue = heartrate.getRate(); //读心率数据 if(rateValue){ Serial.println(rateValue); //串口显示 } delay(20); if(rateValue>=50){ digitalWrite (Relay,HIGH); //大于50输出高电平 delay(100); } else { digitalWrite (Relay,LOW); //小于50输出低电平 delay(100); } }[/mw_shl_code] |
© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed