18106| 15
|
【心率传感器试用】+奥特曼心率灯 |
本帖最后由 nicho 于 2016-12-8 11:01 编辑 实现的效果如上图..... @DFRobot @luna 需要的东东 ---------------------------- Arduino UNO*1 DF心率传感器*1 RBGLED模块*1 LC12S无线模块*1 本来打算使用DF的Bluno来实现心率同步的效果的,但困于ble的开发... 于是想到了之前用过的一款性价比极高的无线模块,LC12s某宝有卖 可以实现在同一频道下串口数据透传,那么为什么需要这么一个模块呢 这个项目除了心率的显示之外,还有一个遇到相同心率的人的时候爆闪的功能 Arduino在读取了心率的数据之后,同时会通过LC12s无线模块广播自身的心率值 同时也会接受频道内其他的心率值,遇到数值相同的时候,爆闪,好像挺酷的 1.首先,我们需要一个奥特曼外壳根据RGBLED大小来设计 大概的外形就是这样了 开打 然后用热熔胶固定一下LED模块就可以了 刷程序进去看看效果 视频演示效果(好像看视频没什么特别的饿...呃...紧张的那部分因为没有去跑步,改了一点数值来拍视频的....) 心率传感器的库里面的关于无效数值的这部分有时候会奇怪,而且模块要放在手上一段时间才会出数据,并且剧烈抖动的时候会比较不准 实际使用的时候,驱动可以自己写,或者直接读取模拟量,至于数值误差这部分,可以根据项目的需要进行过滤 下面的代码是常规写法的DIGITAL_MODE [mw_shl_code=c,true]#define heartratePin A1 #define LED_R 9 #define LED_G 10 #define LED_B 11 #define LC12s_init_pin 5 #include "DFRobot_Heartrate.h" DFRobot_Heartrate heartrate(DIGITAL_MODE); ///< ANALOG_MODE or DIGITAL_MODE char inputString; // a string to hold incoming data boolean stringComplete = false; // whether the string is complete void setup() { pinMode(LED_R, OUTPUT); pinMode(LED_G, OUTPUT); pinMode(LED_B, OUTPUT); pinMode(LC12s_init_pin, OUTPUT); digitalWrite(LED_G, LOW); digitalWrite(LED_R, LOW); digitalWrite(LED_B, LOW); digitalWrite(LC12s_init_pin, HIGH); Serial.begin(9600); // reserve 200 bytes for the inputString: //inputString.reserve(200); delay(500); LC12s();//无线模块初始化 } void loop() { uint8_t rateValue; heartrate.getValue(heartratePin); ///< A1 foot sampled values rateValue = heartrate.getRate(); ///< Get heart rate value if(rateValue) { Serial.println(rateValue); //rateValue分级 LEDMode(rateJudge(rateValue)); delay(20); } if (inputString==rateValue) {//遇到相同频率的心跳信号的时候执行 LEDMode(5); } } int LC12s() {//初始化LC12s模块 char initCode[] = {0xAA,0X5A,0X22,0X33,0X11,0X21,0X00,0X00,0X00,0X04,0X00,0X64,0X00,0X00,0X00,0X12,0X00,0X05}; digitalWrite(LC12s_init_pin, LOW);//拉低set引脚进行组网操作 delay(100); for(int i=0; i<17; i++){ Serial.print(initCode); } delay(100); digitalWrite(LC12s_init_pin, HIGH); delay(500); } void LEDMode(int rateLevel) { switch (rateLevel) { case 0: // do something digitalWrite(LED_R, LOW); digitalWrite(LED_B, LOW); digitalWrite(LED_G, HIGH);//green break; case 1: // do something digitalWrite(LED_G, LOW); digitalWrite(LED_R, LOW); for(int i=0;i<5;i++) { for(int i=0;i<255;i++) { analogWrite(LED_B, i); delay(10); } for(int i=255;i>0;i--) { analogWrite(LED_B, i); delay(10); }} break; case 2: // do something digitalWrite(LED_R, LOW); //digitalWrite(LED_B, HIGH); //digitalWrite(LED_G, HIGH);//bule&green for(int i=0;i<5;i++) { for(int i=0;i<255;i++) { analogWrite(LED_B, i); analogWrite(LED_G, i); delay(3); } for(int i=255;i>0;i--) { analogWrite(LED_B, i); analogWrite(LED_G, i); delay(3); }} break; case 3: // do something digitalWrite(LED_G, LOW); digitalWrite(LED_B, LOW); //digitalWrite(LED_R, HIGH);//red for(int i=0;i<5;i++) { for(int i=0;i<255;i++) { analogWrite(LED_R, i); delay(1); } for(int i=255;i>0;i--) { analogWrite(LED_R, i); delay(1); }} break; case 4: // do something break; case 5: //当遇到心跳频率一样的信号的时候执行 for(int i=0; i<5 ; i++){ for(int i=0;i<255;i++) { analogWrite(LED_R, i); analogWrite(LED_G, i); delay(1); } for(int i=255;i>0;i--) { analogWrite(LED_R, i); analogWrite(LED_G, i); delay(1); } } break; default: // do something break; } } int rateJudge(int rateVal) {//心跳频率分级 if(rateVal<=30){ return 0; } if(rateVal>30&&rateVal<60){ return 1; } if(rateVal>=60&&rateVal<=80){ return 2; } if(rateVal>80&&rateVal<=110){ return 3; } if(rateVal>110&&rateVal<=130){ return 4; } else { return -1; } } /* SerialEvent occurs whenever a new data comes in the hardware serial RX. This routine is run between each time loop() runs, so using delay inside loop can delay response. Multiple bytes of data may be available. */ void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // add it to the inputString: inputString += inChar; // if the incoming character is a newline, set a flag // so the main loop can do something about it: if (inChar == '\n') { stringComplete = true; } //the data was save at (inputstring(included "\n")) } } [/mw_shl_code] DFRobot_Heartrate-master.zip DFRobot_Heartrate-master.zip 一个简单的模型.rar |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed