422234 发表于 2016-11-13 23:44:21

【作业】情绪灯!没人交作业的话我先来一个简单的小作...

本帖最后由 422234 于 2016-11-14 10:26 编辑

迟迟没人交作业。。。。我先来个简单的东西吧!
心率情绪灯
根据心率值,变换不同的颜色,来看你的情绪!!!
材料:
心率传感器*1
bluno控制板(其他的也可以的)
ws2812灯带




http://v.youku.com/v_show/id_XMTgxNzkxODQ4OA==.html

注意听我的娇喘,呼气太快颜色也在变化,闪的频率也在变。
(不要喘太快,尽量稳点提速,心率传感器监测心率时变化太快会不输出值的。。。。。。
而且传感器有点不灵敏。。。不要压太紧也不要离太远,有数据后要保持不动)
还没喘到120以上。。。累{:5_190:}完了可以试试看看女神会不会变成粉色。
/*
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;
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 (inti = 0; i < NUM_LEDS; i++)
{
leds.r = r;
leds.g = g;
leds.b = b;
}
}
库文件



dsweiliang 发表于 2016-11-14 00:06:31


源代码 发表于 2016-11-14 00:25:17

做在衣服上应该效果更好{:5_159:}

422234 发表于 2016-11-14 10:27:27

dsweiliang 发表于 2016-11-14 00:06


多谢大大

luna 发表于 2016-11-14 10:27:35

dsweiliang 发表于 2016-11-14 00:06


{:5_196:} 腻害!发现社区贴代码的新功能~~

吹口琴的钢铁侠 发表于 2016-11-15 10:38:17

dsweiliang 发表于 2016-11-14 00:06


选择c++比较好吧 shell的高亮不好

dsweiliang 发表于 2016-11-15 14:01:46

吹口琴的钢铁侠 发表于 2016-11-15 10:38
选择c++比较好吧 shell的高亮不好

学习了

1050058973 发表于 2018-10-23 18:25:39

楼主有连线的图解吗?作为一个新手小白表示连线很有压力。拜托了

gada888 发表于 2018-10-28 10:14:01

强力顶贴

Topcraz 发表于 2020-2-10 18:39:29

这个是和流光溢彩程序差不多,里面用到好多生僻用法,研究了好长时间

20060606 发表于 2020-8-5 06:13:09

dsweiliang 发表于 2016-11-14 00:06


什么意思

dsweiliang 发表于 2020-8-9 10:17:23

20060606 发表于 2020-8-5 06:13
什么意思

什么什么意思?

20060606 发表于 2020-8-18 10:45:16

dsweiliang 发表于 2020-8-9 10:17
什么什么意思?

交作业是什么意思
页: [1]
查看完整版本: 【作业】情绪灯!没人交作业的话我先来一个简单的小作...