10572| 12
|
[进阶] 【作业】情绪灯!没人交作业的话我先来一个简单的小作... |
本帖最后由 422234 于 2016-11-14 10:26 编辑 迟迟没人交作业。。。。我先来个简单的东西吧! 心率情绪灯 根据心率值,变换不同的颜色,来看你的情绪!!! 材料: 心率传感器*1 bluno控制板(其他的也可以的) ws2812灯带 ![]() ![]() ![]() ![]() 注意听我的娇喘,呼气太快颜色也在变化,闪的频率也在变。 (不要喘太快,尽量稳点提速,心率传感器监测心率时变化太快会不输出值的。。。。。。 而且传感器有点不灵敏。。。不要压太紧也不要离太远,有数据后要保持不动) 还没喘到120以上。。。累 ![]() [mw_shl_code=bash,true]/* Name: Heart text2.ino Created: 2016/11/3 14:16:31 Author: hb */ #include "FastSPI_LED2.h" #define OUTPUT_PORT 7//输出端口 #define NUM_LEDS 61 //灯珠数 #define heartratePin A1 #include "DFRobot_Heartrate.h" int iLed = 0; struct CRGB { byte g; byte r; byte b; }; struct CRGB leds[NUM_LEDS]; DFRobot_Heartrate heartrate(DIGITAL_MODE); WS2811Controller800Mhz<7> LED; byte color_r1 = 250; byte color_g1 = 0; byte color_b1 = 0;//红色 byte color_r2 = 0; byte color_g2 = 255; byte color_b2 = 0;//绿色 byte color_r3 = 0; byte color_g3 = 0; byte color_b3 = 255;//蓝色 byte color_r4 = 255; byte color_g4 = 0; byte color_b4 = 255;//粉色 byte color_r5 = 255; byte color_g5 = 127; byte color_b5 = 0;//橙色 //#ifdef DEBUG //#define DPRINT Serial.print //#define DPRINTLN Serial.println //#else //#define DPRINT(x) //#define DPRINTLN(x) //#endif // the setup function runs once when you press reset or power the board void setup() { Serial.begin(115200); LED.init(); } // the loop function runs over and over again until power down or reset void loop() { memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));//初始化。全部置为0 LED.showRGB((byte*)leds, NUM_LEDS); uint8_t rateValue; heartrate.getValue(heartratePin); ///< A1 foot sampled values rateValue = heartrate.getRate(); ///< Get heart rate value if (rateValue) { Serial.println(rateValue); if (rateValue)//这里判断了两次,是因为你要是在上面那个里直接写的话传感器会疯了似的无限刷新。。。鬼知道为什么! { //memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));//初始化。全部置为0 //LED.showRGB((byte*)leds, NUM_LEDS); if (rateValue >= 60 && rateValue < 80) { setColor(color_r1, color_g1, color_b1); } if (rateValue >= 80 && rateValue < 90) { setColor(color_r2, color_g2, color_b2); } if (rateValue >= 90 && rateValue < 100) { setColor(color_r3, color_g3, color_b3); } if (rateValue >= 100&& rateValue<110) { setColor(color_r5, color_g5, color_b5); } if (rateValue >= 120) { setColor(color_r4, color_g4, color_b4); } LED.showRGB((byte*)leds, NUM_LEDS);; delay(40); } } delay(20); } void setColor(byte r,byte g, byte b) { for (int i = 0; i < NUM_LEDS; i++) { leds.r = r; leds.g = g; leds.b = b; } }[/mw_shl_code] ![]() |
© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed