8369| 0
|
魔幻玫瑰[RGB_LED+3D打印+Arduino红外手势传感器] |
魔幻玫瑰 了解玫瑰,我们才懂欣赏它的美: 原产地中国,多达一百多种 有红色、粉色、白色、黑色、黄色,紫色、 浅绿色,橙色,蓝色,橘红色,彩虹色等 名称有“黑美人”“碧海云天”“紫影” “红衣主教”“海洋之歌”“蓝色妖姬” “金香玉”“冷美人”...... 各种各样的准备小礼物的办法,其中一种有意思的是DIY!因为 “买狠简单,造更有趣” 造 起 来... 为了做成“永不凋谢的玫瑰”,3D打印小白的我开始搜索打印资料 rose.stl rose-closed.stl ROSE模型文件链接【包含花柄支架等】 打印过程中,碰巧有小伙伴来做客。 在等待打印中,聆听着“咝咝”“嗡嗡” 探着小脑袋仔细瞅瞅这儿,还想摸摸这儿摸摸那儿 不时地问这问那的... “永不凋谢”已经完成,那么 怎么做到魔幻色彩呢?变才是根本! 1600万种颜色变换、颜色渐变,非RGB_LED莫属 魔法手势变换,也做得简单、灵敏 准备清单:
【注】RGB_LED实测应该是共阴极吧,接线如下图所示 简单的手势,快速的反应 UNO 可提供两朵花的颜色渐变【D9D10D11,D3D5D6】 [mw_shl_code=cpp,true]/**************************************************************** * 20180330Bir. APDS-9960 RGB and Gesture Sensor Shawn Hymel @ SparkFun Electronics May 30, 2014 Tests the gesture sensing abilities of the APDS-9960. Configures APDS-9960 over I2C and waits for gesture events. Calculates the direction of the swipe (up, down, left, right) and displays it on a serial console. To perform a NEAR gesture, hold your hand far above the sensor and move it close to the sensor (within 2 inches). Hold your hand there for at least 1 second and move it away. To perform a FAR gesture, hold your hand within 2 inches of the sensor for at least 1 second and then move it above (out of range) of the sensor. Hardware Connections: Arduino Pin APDS-9960 Board Function 3.3-5V VCC Power GND GND Ground A4 SDA I2C Data A5 SCL I2C Clock 2 INT Interrupt *******************Modify the description********************** 3.3V-5V VCC Power Void loop () to increase serial port statement causes the wave, will not stop Library function will be waved in recognition of the changed *************************** eg."myledRoseW" RGB_LED Connection: R-D9 G-D10 B-D11 GND-Gnd ***************************/ #include <RGBLED.h> #include <Wire.h> #include <SparkFun_APDS9960.h> // Pins #define APDS9960_INT 2 // Needs to be an interrupt pin // Constants // Global Variables RGBLED myledRoseW = RGBLED(9,10,11); //White big flower 9:Red 10:Green 11:Blue RGBLED myledRoseY = RGBLED(7,8,12); // Yellow big flower RGBLED myledRoseWS = RGBLED(3,5,6); // White small RGBLED myledRoseYS = RGBLED(A0,A1,A2); // Yellow small SparkFun_APDS9960 apds = SparkFun_APDS9960(); int isr_flag = 0; void setup() { // Initialize Serial port Serial.begin(9600); Serial.println(); Serial.println(F("--------------------------------")); Serial.println(F("SparkFun APDS-9960 - GestureTest")); Serial.println(F("--------------------------------")); // Initialize interrupt service routine attachInterrupt(0, interruptRoutine, FALLING); // Initialize APDS-9960 (configure I2C and initial values) if ( apds.init() ) { Serial.println(F("APDS-9960 initialization complete")); } else { Serial.println(F("Something went wrong during APDS-9960 init!")); } // Start running the APDS-9960 gesture sensor engine if ( apds.enableGestureSensor(true) ) { Serial.println(F("Gesture sensor is now running")); } else { Serial.println(F("Something went wrong during gesture sensor init!")); } } //////////////////////////////////////////////// void loop() { if( isr_flag == 1 ) { handleGesture(); if(digitalRead(APDS9960_INT) == 0){ apds.init(); apds.enableGestureSensor(true); } isr_flag = 0; } } //////////////////////////////////////////////// void interruptRoutine() { isr_flag = 1; } //////////////////////////////////////////////// void handleGesture() { if ( apds.isGestureAvailable() ) { switch ( apds.readGesture() ) { case DIR_UP: Serial.println("Red"); myledRoseW.colorRGB(255,0,0); myledRoseY.colorRGB(255,0,0); myledRoseWS.colorRGB(255,0,0); myledRoseYS.colorRGB(255,0,0); break; case DIR_DOWN: Serial.println("OFF"); myledRoseW.colorRGB(0,0,0); myledRoseY.colorRGB(0,0,0); myledRoseWS.colorRGB(0,0,0); myledRoseYS.colorRGB(0,0,0); break; case DIR_LEFT: Serial.println("Green"); myledRoseW.colorRGB(0,255,0); myledRoseY.colorRGB(0,255,0); myledRoseWS.colorRGB(0,255,0); myledRoseYS.colorRGB(0,255,0); break; case DIR_RIGHT: Serial.println("Blue"); myledRoseW.colorRGB(0,0,255); myledRoseY.colorRGB(0,0,255); myledRoseWS.colorRGB(0,0,255); myledRoseYS.colorRGB(0,0,255); break; case DIR_NEAR: Serial.println("Breath"); breathLED(); break; case DIR_FAR: Serial.println("VARITY"); colorLedHSV(); break; default: Serial.println("NONE"); // WHITE LIGHT myledRoseW.colorRGB(255,255,255); myledRoseY.colorRGB(255,255,255); myledRoseWS.colorRGB(255,255,255); myledRoseYS.colorRGB(255,255,255); break; } } } //////////////////////////////////////////////// void colorLedHSV(){ for(int j = 0;j < 360; j++){ myledRoseW.colorHSV(j,255,255); //H:0-360 S:0-255 V:0-255 myledRoseY.colorHSV(j,255,255); myledRoseWS.colorHSV(j,255,255); myledRoseYS.colorHSV(j,255,255); delay(20); } } //////////////////////////////////////////////// void breathLED(){ for(int i = random(0,10);i <= 255;i++){ myledRoseW.colorRGB(i,i,i); myledRoseY.colorRGB(i,i,i); myledRoseWS.colorRGB(i,i,i); myledRoseYS.colorRGB(i,i,i); delay(20); } for(int i = 255;i >= random(0,10);i--){ myledRoseW.colorRGB(i,i,i); myledRoseY.colorRGB(i,i,i); myledRoseWS.colorRGB(i,i,i); myledRoseYS.colorRGB(i,i,i); delay(20); } // WHITE delay(200); for(int i = random(0,10);i <= 255;i++){ myledRoseW.colorRGB(i,0,0); myledRoseY.colorRGB(i,0,0); myledRoseWS.colorRGB(i,0,0); myledRoseYS.colorRGB(i,0,0); delay(20); } for(int i = 255;i >= random(0,10);i--){ myledRoseW.colorRGB(i,0,0); myledRoseY.colorRGB(i,0,0); myledRoseWS.colorRGB(i,0,0); myledRoseYS.colorRGB(i,0,0); delay(20); } // RED delay(200); for(int i = random(0,10);i <= 255;i++){ myledRoseW.colorRGB(0,i,0); myledRoseY.colorRGB(0,i,0); myledRoseWS.colorRGB(0,i,0); myledRoseYS.colorRGB(0,i,0); delay(20); } for(int i = 255;i >= random(0,10);i--){ myledRoseW.colorRGB(0,i,0); myledRoseY.colorRGB(0,i,0); myledRoseWS.colorRGB(0,i,0); myledRoseYS.colorRGB(0,i,0); delay(20); } // GREEN delay(200); for(int i = random(0,10);i <= 255;i++){ myledRoseW.colorRGB(0,0,i); myledRoseY.colorRGB(0,0,i); myledRoseWS.colorRGB(0,0,i); myledRoseYS.colorRGB(0,0,i); delay(20); } for(int i = 255;i >= random(0,10);i--){ myledRoseW.colorRGB(0,0,i); myledRoseY.colorRGB(0,0,i); myledRoseWS.colorRGB(0,0,i); myledRoseYS.colorRGB(0,0,i); delay(20); } // BLUE } //////////////////////////////////////////////// [/mw_shl_code] |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed