用3D手势传感器制作一个蘑菇灯
作者:吴磊今天买了1个3D手势识别迷你传感器,恩,对,就是3D手势识别迷你传感器,测试一下后,发现挺有意思的,想赶紧做一个东西出来看看效果。3D、3D,对就用3D打印机打印个东西,打印什么呢,像动画偏离的大蘑菇,不如做个大蘑菇灯吧。
视频效果https://imgcache.qq.com/tencentvideo_v1/playerv3/TPout.swf?max_age=86400&v=20161117&vid=i0511fugbk4&auto=0
▲3D打印图
材料清单SEN0202 3D手势识别迷你传感器 x1 WS2812 RGB LED Module x5 DFRduino UNO R3 x1 7.4V 2500MA 锂电池 x1 9V/1000mA开关电源适配器 x1
连接标注【传感器】
3D手势传感器 UNO R3控制板VCC -> 5VGND -> GNDSCL -> SCLSDK -> SDKD -> D8MCLR -> D9
【RGB灯】
WS2812 RGB LED ModuleVCC -> 5VGND -> GNDD -> D7
装配图
模型下载:
程序代码#include <Adafruit_NeoPixel.h>
#include <DFRobot_Gesture.h>
#include <Wire.h>
#define Lamp 6 //黄灯
#define Dio 8 //数字IO口
#define MCLR 9 //传感器复位(低电平有效)
#define PIN 10 //灯IO
#define NUMBER 7 //共有5个灯
unsigned char cmd;
unsigned long RGBtime = 0, RGBtime1 = 0, RGBtime2 = 0;
uint32_t a1 = 0, b1 = 1, c1 = 2,d1 = 3, e1 = 4, a2 = 0, b2 = 1, c2 = 2, d2 = 3, e2 = 4;
uint32_t Light = 0;//灯的亮度
unsigned int dstance_1, dstance_2, dstance_3, dstance_4, dstance_5, dstance_6, dstance_7, dstance_8, dstance_9;
unsigned int Mark = 1; //1:红色(255,0,0),2:绿色(0, 255, 0),3:蓝色(0, 0, 255),4:黄色(255, 255, 0)
//5:蓝绿色(0, 255, 255),6:品红色(255, 0, 255),7:白色(255, 255, 255)
DFRobot_Gesture myGesture;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMBER, PIN, NEO_GRB + NEO_KHZ800); //灯参数
void distance()
{
dstance_1 = 0;
dstance_2 = 0;
dstance_3 = 0;
dstance_4 = 0;
dstance_5 = 0;
dstance_6 = 0;
dstance_7 = 0;
dstance_8 = 0;
dstance_9 = 0;
}
void RGB_0(uint32_t x, uint32_t a, uint32_t b, uint32_t c) //RGB灯1个灯亮一个颜色
{
strip.setPixelColor(x, strip.Color( a, b, c) ); //0,指第1个RGB灯,后面的值是R,G,B其值为0-255
strip.show();
}
void RGB_1(uint32_t a, uint32_t b, uint32_t c)//RGB灯4个灯亮同一个颜色
{
strip.setPixelColor(0, strip.Color( a, b, c) ); //0,指第1个RGB灯,后面的值是R,G,B其值为0-255
strip.setPixelColor(1, strip.Color( a, b, c) ); //
strip.setPixelColor(2, strip.Color( a, b, c) );
strip.setPixelColor(3, strip.Color( a, b, c) );
strip.setPixelColor(4, strip.Color( a, b, c) );
strip.setPixelColor(5, strip.Color( a, b, c) );
strip.setPixelColor(6, strip.Color( a, b, c) );
strip.show();
}
void RGB_2(uint32_t x, uint32_t y, uint32_t a, uint32_t b, uint32_t c) //RGB灯2个灯亮同一个颜色
{
strip.setPixelColor(x, strip.Color( a, b, c) ); //0,指第1个RGB灯,后面的值是R,G,B其值为0-255
strip.setPixelColor(y, strip.Color( a, b, c) ); //
strip.show();
}
void RGB_3(uint32_t a, uint32_t b, uint32_t c) //3个RGB灯亮红绿蓝3个颜色
{
strip.setPixelColor(a, strip.Color( 255, 0, 0) ); //a,指第a+1位上的RGB灯,从0开始;后面的值是R,G,B其值为0-255
strip.setPixelColor(b, strip.Color( 0, 255, 0) ); //
strip.setPixelColor(c, strip.Color( 0, 0, 255) );
strip.show();
}
void RGB_4(uint32_t a, uint32_t b, uint32_t c, uint32_t d) //4个RGB灯亮红绿蓝白四个颜色
{
strip.setPixelColor(a, strip.Color( 255, 0, 0) ); //a,指第a+1位上的RGB灯,从0开始;后面的值是R,G,B其值为0-255
strip.setPixelColor(b, strip.Color( 0, 255, 0) ); //
strip.setPixelColor(c, strip.Color( 0, 0, 255) );
strip.setPixelColor(d, strip.Color( 255, 255, 255) );
strip.show();
}
void setup()
{
Wire.begin();
strip.begin(); //启动RGB灯
Serial.begin(115200); // 打开串口,设置速率为115200 bps
pinMode(Dio, INPUT);
pinMode(MCLR, OUTPUT);
pinMode(Lamp,OUTPUT);
digitalWrite(MCLR, HIGH);
digitalWrite(Lamp,LOW);
}
void loop()
{
if (Mark == 0)//
Mark = 7;
if (Mark == 8)//
Mark = 1;
delay(50);
switch (Mark)//选择亮那种颜色的灯
{
case 1:
RGB_1(Light, 0, 0);
break;
case 2:
RGB_1(0, Light, 0);
break;
case 3:
RGB_1(0, 0, Light);
break;
case 4:
RGB_1(Light, Light, 0);
break;
case 5:
RGB_1(0, Light, Light);
break;
case 6:
RGB_1(Light, 0, Light);
break;
case 7:
RGB_1(Light, Light, Light);
break;
default:
RGB_1(0, 0, 0);
digitalWrite(Lamp,LOW);
}
if (digitalRead(Dio) == 0)//判断
{
myGesture.I2C1_MasterRead(md.buf, 26, 0x42); //The address is:0x42
cmd = myGesture.mgcProcMsg(); //process the message
if (md.sensorData.posZ > 0 && md.sensorData.posZ < 8000) //距离
{
Light = 255;
digitalWrite(Lamp,HIGH);
}
else if (md.sensorData.posZ >= 8000 && md.sensorData.posZ < 15000)//
{
Light = 220;
digitalWrite(Lamp,HIGH);
}
else if (md.sensorData.posZ >= 15000 && md.sensorData.posZ < 22000) //
{
Light = 185;
digitalWrite(Lamp,HIGH);
}
else if (md.sensorData.posZ >= 22000 && md.sensorData.posZ < 29000)
{
Light = 150;
digitalWrite(Lamp,HIGH);
}
else if (md.sensorData.posZ >= 29000 && md.sensorData.posZ < 36000)
{
Light = 120;
digitalWrite(Lamp,HIGH);
}
else if (md.sensorData.posZ >= 36000 && md.sensorData.posZ < 44000)
{
Light = 80;
digitalWrite(Lamp,HIGH);
}
else if (md.sensorData.posZ >= 44000 && md.sensorData.posZ < 52000)
{
Light = 50;
digitalWrite(Lamp,HIGH);
}
else if (md.sensorData.posZ >= 52000 && md.sensorData.posZ < 60000)
{
Light = 20;
digitalWrite(Lamp,HIGH);
}
else if (md.sensorData.posZ >= 60000 && md.sensorData.posZ < 65000 )
{
Light = 0;
digitalWrite(Lamp,LOW);
}
if (cmd != GI_NOGESTURE )//
{
if (cmd == GI_AIRWHEEL_CW)//顺时针转
{
Serial.println("CW");
Mark += 1;
}
else if (cmd == GI_AIRWHEEL_CCW)//逆时针转
{
Serial.println("CCW");
Mark -= 1;
}
}
}
}
代码压缩包下载:
小伙伴们赶快行动吧,特别是晚上,看着挺美的哦!
好漂亮呀 本帖最后由 O_oYYQ 于 2017-6-8 14:25 编辑
我也有这个DF的手势传感器 赶紧学着做起来哈哈哈 O_oYYQ 发表于 2017-6-8 14:07
我也有这个DF的手势传感器 赶紧学着做起来哈哈哈
:lol 蘑菇云的意向吗? 哈哈哈 饶厂长 发表于 2017-6-9 15:20
蘑菇云的意向吗? 哈哈哈
那倒是没有~主要是蘑菇的造型会比较适合做灯 谢谢楼主 但是想问可用LED灯带吗 saudade 发表于 2018-5-5 22:13
谢谢楼主 但是想问可用LED灯带吗
是可以的
页:
[1]