查看: 3572|回复: 0

魔幻玫瑰[RGB_LED+3D打印+Arduino红外手势传感器]

[复制链接]
魔幻玫瑰

IMG_20180403_113957.jpg


IMG_20180403_113932.jpg

了解玫瑰,我们才懂欣赏它的美:
原产地中国,多达一百多种
有红色、粉色、白色、黑色、黄色,紫色、
浅绿色,橙色,蓝色,橘红色,彩虹色等
名称有“黑美人”“碧海云天”“紫影”
“红衣主教”“海洋之歌”“蓝色妖姬”
“金香玉”“冷美人”......

各种各样的准备小礼物的办法,其中一种有意思的是DIY!因为
“买狠简单,造更有趣”
造 起 来...
为了做成“永不凋谢的玫瑰”,3D打印小白的我开始搜索打印资料
rose-0.png
rose.stl
rose-1.png
rose-closed.stl
ROSE模型文件链接【包含花柄支架等】

Screenshot_2018-03-31-21-.png

打印过程中,碰巧有小伙伴来做客。
在等待打印中,聆听着“咝咝”“嗡嗡”
探着小脑袋仔细瞅瞅这儿,还想摸摸这儿摸摸那儿
不时地问这问那的...

8888.jpg
“永不凋谢”已经完成,那么
怎么做到魔幻色彩呢?变才是根本!
1600万种颜色变换、颜色渐变,非RGB_LED莫属
魔法手势变换,也做得简单、灵敏
准备清单:

【注】RGB_LED实测应该是共阴极吧,接线如下图所示
IMG_20180331_182250.jpg

IMG_20180331_213451_HDR.jpg

简单的手势,快速的反应

UNO 可提供两朵花的颜色渐变【D9D10D11,D3D5D6】

[C++] 纯文本查看 复制代码
/****************************************************************[/align]
[align=left]* 20180330Bir.[/align]
[align=left]APDS-9960 RGB and Gesture Sensor[/align]
[align=left]Shawn Hymel @ SparkFun Electronics[/align]
[align=left]May 30, 2014[/align]
[align=left][url=https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor]https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor[/url][/align]

[align=left]Tests the gesture sensing abilities of the APDS-9960. Configures[/align]
[align=left]APDS-9960 over I2C and waits for gesture events. Calculates the[/align]
[align=left]direction of the swipe (up, down, left, right) and displays it[/align]
[align=left]on a serial console. [/align]

[align=left]To perform a NEAR gesture, hold your hand[/align]
[align=left]far above the sensor and move it close to the sensor (within 2[/align]
[align=left]inches). Hold your hand there for at least 1 second and move it[/align]
[align=left]away.[/align]

[align=left]To perform a FAR gesture, hold your hand within 2 inches of the[/align]
[align=left]sensor for at least 1 second and then move it above (out of[/align]
[align=left]range) of the sensor.[/align]

[align=left]Hardware Connections:[/align]

[align=left]Arduino Pin  APDS-9960 Board  Function[/align]
 
[align=left]3.3-5V         VCC              Power[/align]
[align=left]GND          GND              Ground[/align]
[align=left]A4           SDA              I2C Data[/align]
[align=left]A5           SCL              I2C Clock[/align]
[align=left]2            INT              Interrupt[/align]


[align=left]*******************Modify the description**********************[/align]
[align=left]3.3V-5V     VCC       Power[/align]
[align=left]Void loop () to increase serial port statement causes the wave, will not stop[/align]
[align=left]Library function will be waved in recognition of the changed[/align]
[align=left]***************************[/align]
[align=left]eg."myledRoseW" RGB_LED Connection:[/align]
[align=left]     R-D9[/align]
[align=left]     G-D10[/align]
[align=left]     B-D11[/align]
[align=left]     GND-Gnd[/align]
[align=left]***************************/[/align]
[align=left]#include <RGBLED.h>[/align]
[align=left]#include <Wire.h>[/align]
[align=left]#include <SparkFun_APDS9960.h>[/align]

[align=left]// Pins[/align]
[align=left]#define APDS9960_INT    2 // Needs to be an interrupt pin[/align]

[align=left]// Constants[/align]

[align=left]// Global Variables[/align]
[align=left]RGBLED myledRoseW = RGBLED(9,10,11); //White big flower 9:Red  10:Green   11:Blue[/align]
[align=left]RGBLED myledRoseY = RGBLED(7,8,12); // Yellow big flower[/align]
[align=left]RGBLED myledRoseWS = RGBLED(3,5,6); // White small[/align]
[align=left]RGBLED myledRoseYS = RGBLED(A0,A1,A2); // Yellow small[/align]
[align=left]SparkFun_APDS9960 apds = SparkFun_APDS9960();[/align]
[align=left]int isr_flag = 0;[/align]

[align=left]void setup() {[/align]

[align=left]  // Initialize Serial port[/align]
[align=left]  Serial.begin(9600);[/align]
[align=left]  Serial.println();[/align]
[align=left]  Serial.println(F("--------------------------------"));[/align]
[align=left]  Serial.println(F("SparkFun APDS-9960 - GestureTest"));[/align]
[align=left]  Serial.println(F("--------------------------------"));[/align]

[align=left]  // Initialize interrupt service routine[/align]
[align=left]  attachInterrupt(0, interruptRoutine, FALLING);[/align]

[align=left]  // Initialize APDS-9960 (configure I2C and initial values)[/align]
[align=left]  if ( apds.init() ) {[/align]
[align=left]    Serial.println(F("APDS-9960 initialization complete"));[/align]
[align=left]  } else {[/align]
[align=left]    Serial.println(F("Something went wrong during APDS-9960 init!"));[/align]
[align=left]  }[/align]

[align=left]  // Start running the APDS-9960 gesture sensor engine[/align]
[align=left]  if ( apds.enableGestureSensor(true) ) {[/align]
[align=left]    Serial.println(F("Gesture sensor is now running"));[/align]
[align=left]  } else {[/align]
[align=left]    Serial.println(F("Something went wrong during gesture sensor init!"));[/align]
[align=left]  }[/align]
[align=left]}[/align]
[align=left]////////////////////////////////////////////////[/align]
[align=left]void loop() {[/align]
[align=left]  if( isr_flag == 1 ) {[/align]
[align=left]    handleGesture();[/align]
[align=left]      if(digitalRead(APDS9960_INT) == 0){[/align]
[align=left]      apds.init();[/align]
[align=left]      apds.enableGestureSensor(true);[/align]
[align=left]    }[/align]
[align=left]    isr_flag = 0;[/align]
[align=left]  }[/align]
[align=left]}[/align]
[align=left]////////////////////////////////////////////////[/align]
[align=left]void interruptRoutine() {[/align]
[align=left]  isr_flag = 1;[/align]
[align=left]}[/align]
[align=left]////////////////////////////////////////////////[/align]
[align=left]void handleGesture() {[/align]
[align=left]    if ( apds.isGestureAvailable() ) {[/align]
[align=left]    switch ( apds.readGesture() ) {[/align]
[align=left]      case DIR_UP:[/align]
[align=left]        Serial.println("Red");[/align]
[align=left]        myledRoseW.colorRGB(255,0,0);[/align]
[align=left]        myledRoseY.colorRGB(255,0,0);[/align]
[align=left]        myledRoseWS.colorRGB(255,0,0);[/align]
[align=left]        myledRoseYS.colorRGB(255,0,0);[/align]
[align=left]        break;[/align]
[align=left]      case DIR_DOWN:[/align]
[align=left]        Serial.println("OFF");[/align]
[align=left]        myledRoseW.colorRGB(0,0,0);[/align]
[align=left]        myledRoseY.colorRGB(0,0,0);[/align]
[align=left]        myledRoseWS.colorRGB(0,0,0);[/align]
[align=left]        myledRoseYS.colorRGB(0,0,0);[/align]
[align=left]        break;[/align]
[align=left]      case DIR_LEFT:[/align]
[align=left]        Serial.println("Green");[/align]
[align=left]        myledRoseW.colorRGB(0,255,0);[/align]
[align=left]        myledRoseY.colorRGB(0,255,0);[/align]
[align=left]        myledRoseWS.colorRGB(0,255,0);[/align]
[align=left]        myledRoseYS.colorRGB(0,255,0);[/align]
[align=left]        break;[/align]
[align=left]      case DIR_RIGHT:[/align]
[align=left]        Serial.println("Blue");[/align]
[align=left]        myledRoseW.colorRGB(0,0,255);[/align]
[align=left]        myledRoseY.colorRGB(0,0,255);[/align]
[align=left]        myledRoseWS.colorRGB(0,0,255);[/align]
[align=left]        myledRoseYS.colorRGB(0,0,255);[/align]
[align=left]        break;[/align]
[align=left]      case DIR_NEAR:[/align]
[align=left]        Serial.println("Breath");[/align]
[align=left]        breathLED();[/align]
[align=left]        break;[/align]
[align=left]      case DIR_FAR:[/align]
[align=left]        Serial.println("VARITY");[/align]
[align=left]        colorLedHSV();[/align]
[align=left]        break;[/align]
[align=left]      default:[/align]
[align=left]        Serial.println("NONE");  // WHITE LIGHT[/align]
[align=left]        myledRoseW.colorRGB(255,255,255);[/align]
[align=left]        myledRoseY.colorRGB(255,255,255);[/align]
[align=left]        myledRoseWS.colorRGB(255,255,255);[/align]
[align=left]        myledRoseYS.colorRGB(255,255,255);[/align]
[align=left]        break;[/align]
[align=left]    }[/align]
[align=left]  }[/align]
[align=left]}[/align]
[align=left]////////////////////////////////////////////////[/align]
[align=left]void colorLedHSV(){  [/align]
[align=left]for(int j = 0;j < 360; j++){  [/align]
[align=left]myledRoseW.colorHSV(j,255,255); //H:0-360   S:0-255  V:0-255[/align]
[align=left]myledRoseY.colorHSV(j,255,255); [/align]
[align=left]myledRoseWS.colorHSV(j,255,255); [/align]
[align=left]myledRoseYS.colorHSV(j,255,255); [/align]
[align=left]delay(20);[/align]
[align=left]}[/align]
[align=left]}[/align]
[align=left]////////////////////////////////////////////////[/align]
[align=left]void breathLED(){[/align]
[align=left]  for(int i = random(0,10);i <= 255;i++){[/align]
[align=left]    myledRoseW.colorRGB(i,i,i);[/align]
[align=left]    myledRoseY.colorRGB(i,i,i);[/align]
[align=left]    myledRoseWS.colorRGB(i,i,i);[/align]
[align=left]    myledRoseYS.colorRGB(i,i,i);[/align]
[align=left]    delay(20);[/align]
[align=left]  }[/align]
[align=left]  for(int i = 255;i >= random(0,10);i--){[/align]
[align=left]    myledRoseW.colorRGB(i,i,i);[/align]
[align=left]    myledRoseY.colorRGB(i,i,i);[/align]
[align=left]    myledRoseWS.colorRGB(i,i,i);[/align]
[align=left]    myledRoseYS.colorRGB(i,i,i);[/align]
[align=left]    delay(20);[/align]
[align=left]  } // WHITE[/align]
[align=left]  delay(200);[/align]
[align=left]  for(int i = random(0,10);i <= 255;i++){[/align]
[align=left]    myledRoseW.colorRGB(i,0,0);[/align]
[align=left]    myledRoseY.colorRGB(i,0,0);[/align]
[align=left]    myledRoseWS.colorRGB(i,0,0);[/align]
[align=left]    myledRoseYS.colorRGB(i,0,0);[/align]
[align=left]    delay(20);[/align]
[align=left]  }[/align]
[align=left]  for(int i = 255;i >= random(0,10);i--){[/align]
[align=left]    myledRoseW.colorRGB(i,0,0);[/align]
[align=left]    myledRoseY.colorRGB(i,0,0);[/align]
[align=left]    myledRoseWS.colorRGB(i,0,0);[/align]
[align=left]    myledRoseYS.colorRGB(i,0,0);[/align]
[align=left]    delay(20);[/align]
[align=left]  } // RED  [/align]
[align=left]  delay(200);[/align]
[align=left]  for(int i = random(0,10);i <= 255;i++){[/align]
[align=left]    myledRoseW.colorRGB(0,i,0);[/align]
[align=left]    myledRoseY.colorRGB(0,i,0);[/align]
[align=left]    myledRoseWS.colorRGB(0,i,0);[/align]
[align=left]    myledRoseYS.colorRGB(0,i,0);[/align]
[align=left]    delay(20);[/align]
[align=left]  }[/align]
[align=left]  for(int i = 255;i >= random(0,10);i--){[/align]
[align=left]    myledRoseW.colorRGB(0,i,0);[/align]
[align=left]    myledRoseY.colorRGB(0,i,0);[/align]
[align=left]    myledRoseWS.colorRGB(0,i,0);[/align]
[align=left]    myledRoseYS.colorRGB(0,i,0);[/align]
[align=left]    delay(20);[/align]
[align=left]  } // GREEN[/align]
[align=left]  delay(200);[/align]
[align=left]  for(int i = random(0,10);i <= 255;i++){[/align]
[align=left]    myledRoseW.colorRGB(0,0,i);[/align]
[align=left]    myledRoseY.colorRGB(0,0,i);[/align]
[align=left]    myledRoseWS.colorRGB(0,0,i);[/align]
[align=left]    myledRoseYS.colorRGB(0,0,i);[/align]
[align=left]    delay(20);[/align]
[align=left]  }[/align]
[align=left]  for(int i = 255;i >= random(0,10);i--){[/align]
[align=left]    myledRoseW.colorRGB(0,0,i);[/align]
[align=left]    myledRoseY.colorRGB(0,0,i);[/align]
[align=left]    myledRoseWS.colorRGB(0,0,i);[/align]
[align=left]    myledRoseYS.colorRGB(0,0,i);[/align]
[align=left]    delay(20);[/align]
[align=left]  } // BLUE[/align]
[align=left]}[/align]
[align=left]////////////////////////////////////////////////[/align]

[align=left]

RGBLED.zip (2.8 KB, 下载次数: 38)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
wifi气象站

硬件清单

btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2019 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail