才刚过完年没几天,西洋情人节马上就来报到了。对很多人来说,这表示得花点钱买情人节卡片、巧克力或鲜花等传统的礼物,或者是和情人一起吃顿晚餐。虽然都是精心挑选的礼物或营造的气氛,但发自内心且亲手打造的创意设计更让人开心,毕竟它是专为某个人特别制作的,可不是商店货架上就能看到的商品啊! 怎样成功赢得情人脸上那个感动又满意的笑容? 先发个样板视频,有时间再发个成品视频 这次的项目通过一个颜色传感器做的‘盒子’给爱人做演示,让它来识别周围的物体,当识别到你的爱人衣服的颜色(你得事先知道你的爱人的衣服颜色,程序是预先烧录的),接受到信号的别在你衣服上的LED灯会开始做呼吸灯闪烁。这样你就可以跟你的爱人说‘’你看,神奇吧,他们有感应‘’ 工作原理:用色彩模块识别到红色后(也可以设置其他颜色),程序里可选颜色是红,绿,蓝,橙,黄(颜色相似则归于相似色),信号通过433M模块的发射端发送到接收端。接受端得到信号后,会指令LED开始闪烁。 硬件如下: Arduino pro mini x 2 433发射端 433接受端 颜色模块DF-34725 ==================== 接下来是连线图。 发射端连线图 接受端连线图 发射端代码: [mw_shl_code=applescript,false]/*This sketch is made by gada888
--------Luoyang-----China-----
-------2020-02-10----
*/
#include "Wire.h"
#include "Adafruit_TCS34725.h"
#include <VirtualWire.h>
char *controller;
// initialize Color Sensor object
Adafruit_TCS34725 tcs = Adafruit_TCS34725 ( TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_1X ) ;
// setup () is executed once at Arduino startup
void setup ( ) {
// serial communication to output the value in the
Serial. begin ( 9600 ) ;
Serial. println ( "Color Sensor" );
pinMode(13,OUTPUT);
vw_set_ptt_inverted(true); //
vw_set_tx_pin(12);
vw_setup(4000);// speed of data transfer Kbps
// Check if Color Sensor also logs back
if ( tcs. begin ( ) ) {
// Everything OK
Serial. println ( "sensor found" ) ;
} else {
// No sensor found. Freeze program at this point
Serial. println ( "TCS34725 not found ... process stopped!" ) ;
while ( 1 ) ; // Stop!
}
}
// loop () is repeated while the arduino is running
void loop ( ) {
// the sensor returns values 鈥嬧€媐or R, G, B and a clear value
uint16_t clearcol, red, green, blue ;
float average, r, g, b ;
delay ( 100 ) ; // color measurement takes c. 50ms
tcs. getRawData ( & red, & green, &blue, & clearcol ) ;
// my attempt of color determination for
// the 5 M & M colors red, green, blue, orange and yellow
// average of RGB determine
average = ( red + green + blue ) / 3 ;
// color values 鈥嬧€媌y average,
// all values 鈥嬧€媙ow move around 1
r = red / average ;
g = green / average ;
b = blue / average ;
// output the clear value and r, g, b serially for control
// r, g and b should be between approx. 0.5 and 1.5
//. If the sensor looks red, then r should be well above 1.0
//, g and b between 0.5 and 1.0, and so on
Serial. print ( " \ t Clear:" ) ; Serial. print ( clearcol ) ;
Serial. print ( " \ t Red:" ) ; Serial. print ( r ) ;
Serial. print ( " \ t Green:" ) ;Serial. print ( g ) ;
Serial. print ( " \ t Blue:" ) ; Serial. print ( b ) ;
// Attempt to determine the color using the r, g, b values.
// Best start with red, green, blue which adjust the thresholds // with the serial output accordingly
if ( ( r > 1.4 ) && ( g < 0.9 ) && ( b < 0.9 ) ) {
Serial.print ( " \ t RED" ) ;
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,1);
delay(1000);
}
else if ( ( r < 0.95 ) && ( g > 1.4 ) && ( b < 0.9 ) ) {
Serial. print ( " \ t GREEN" ) ;
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(1000);
}
else if ( (r < 0.8 ) && ( g < 1.2 ) && ( b > 1.2 ) ) {
Serial. print ( " \ t BLUE" ) ;
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(1000);
}
// yellow and orange are a bit tricky, but after some
// trying around, these values 鈥嬧€媡urned out to be
//
else if ( ( r > 1.15 ) && ( g > 1.15 ) && ( b < 0.7 ) ) {
Serial. print ( " \ t YELLOW" ) ;
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(1000);
}
else if ( ( r > 1.4 ) && ( g < 1.0 ) && ( b < 0.7 ) ) {
Serial. print ( " \ t ORANGE" ) ;
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(1000);
}
// If no rule works, then be honest
else {
Serial. print ( " \ t NOT RECOGNIZED" ) ;
// myservo.write (nonePos);
}
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(1000);
// output line
Serial. println ( "" ) ;
// adjust wait time for serial debugging
delay ( 100 ) ;
}[/mw_shl_code] 接收端代码: [mw_shl_code=applescript,false]/*This sketch is made by gada888
--------Luoyang-----China-----
-------2020-02-10----
*/
#include "Wire.h"
#include "Adafruit_TCS34725.h"
#include <VirtualWire.h>
char *controller;
// initialize Color Sensor object
Adafruit_TCS34725 tcs = Adafruit_TCS34725 ( TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_1X ) ;
// setup () is executed once at Arduino startup
void setup ( ) {
// serial communication to output the value in the
Serial. begin ( 9600 ) ;
Serial. println ( "Color Sensor" );
pinMode(13,OUTPUT);
vw_set_ptt_inverted(true); //
vw_set_tx_pin(12);
vw_setup(4000);// speed of data transfer Kbps
// Check if Color Sensor also logs back
if ( tcs. begin ( ) ) {
// Everything OK
Serial. println ( "sensor found" ) ;
} else {
// No sensor found. Freeze program at this point
Serial. println ( "TCS34725 not found ... process stopped!" ) ;
while ( 1 ) ; // Stop!
}
}
// loop () is repeated while the arduino is running
void loop ( ) {
// the sensor returns values 鈥嬧€媐or R, G, B and a clear value
uint16_t clearcol, red, green, blue ;
float average, r, g, b ;
delay ( 100 ) ; // color measurement takes c. 50ms
tcs. getRawData ( & red, & green, &blue, & clearcol ) ;
// my attempt of color determination for
// the 5 M & M colors red, green, blue, orange and yellow
// average of RGB determine
average = ( red + green + blue ) / 3 ;
// color values 鈥嬧€媌y average,
// all values 鈥嬧€媙ow move around 1
r = red / average ;
g = green / average ;
b = blue / average ;
// output the clear value and r, g, b serially for control
// r, g and b should be between approx. 0.5 and 1.5
//. If the sensor looks red, then r should be well above 1.0
//, g and b between 0.5 and 1.0, and so on
Serial. print ( " \ t Clear:" ) ; Serial. print ( clearcol ) ;
Serial. print ( " \ t Red:" ) ; Serial. print ( r ) ;
Serial. print ( " \ t Green:" ) ;Serial. print ( g ) ;
Serial. print ( " \ t Blue:" ) ; Serial. print ( b ) ;
// Attempt to determine the color using the r, g, b values.
// Best start with red, green, blue which adjust the thresholds // with the serial output accordingly
if ( ( r > 1.4 ) && ( g < 0.9 ) && ( b < 0.9 ) ) {
Serial.print ( " \ t RED" ) ;
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,1);
delay(1000);
}
else if ( ( r < 0.95 ) && ( g > 1.4 ) && ( b < 0.9 ) ) {
Serial. print ( " \ t GREEN" ) ;
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(1000);
}
else if ( (r < 0.8 ) && ( g < 1.2 ) && ( b > 1.2 ) ) {
Serial. print ( " \ t BLUE" ) ;
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(1000);
}
// yellow and orange are a bit tricky, but after some
// trying around, these values 鈥嬧€媡urned out to be
//
else if ( ( r > 1.15 ) && ( g > 1.15 ) && ( b < 0.7 ) ) {
Serial. print ( " \ t YELLOW" ) ;
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(1000);
}
else if ( ( r > 1.4 ) && ( g < 1.0 ) && ( b < 0.7 ) ) {
Serial. print ( " \ t ORANGE" ) ;
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(1000);
}
// If no rule works, then be honest
else {
Serial. print ( " \ t NOT RECOGNIZED" ) ;
// myservo.write (nonePos);
}
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(1000);
// output line
Serial. println ( "" ) ;
// adjust wait time for serial debugging
delay ( 100 ) ;
}[/mw_shl_code]
|