步骤1:零件清单
对于此项目,我们需要:
tcs34725 rgb颜色传感器对于arduino by dfrobot
带有rgb字体显示的i2c 16x2 arduino lcd dfrobot
dfrobino的dfrduino pro mini v1.3(8m3.3v328)
2 x cr2032电池座
滑动开关
rgb led模块
电线
3x7 cm原型pcb
男性和母针头
2x m2x20螺丝和螺母
工具:
3d打印机,如果你不拥有它,你可以从shapeways获得印花盒
菲利普斯螺丝刀
烙铁
焊接
步骤2:原理图
请参阅下面打开视频的装配部分和示意图,了解如何
使用上面提供的原理图进行正确接线。
2》
在测量完零件后,是时候设计一个3d外壳并进行打印了!
设计
以下是我在tinkercad上的设计链接:https://www.tinkercad.com/things/dg47pr28uwx
上面的内容设计非常适合上面列出的所有组件。
前部将固定lcd屏幕和颜色传感器。
主要的3x7 cm pcb将容纳dfrduino pro mini,电池座和3个按钮,将是从内部拧到后部。
rgb led将位于后部顶部内部。
电源开关将安装在后部的小孔中。
打印
准备打印的3d模型是av适用于thingiverse:https://www.thingiverse.com/thing:3223709
打印设置可能因打印机而异。
电池盖部件和前部需要支撑因为前部有一个内置的距离,可以提供颜色传感器和样品之间的距离。
如果你没有3d打印机,你可以从shapeways获得印刷品:点击这里
汇编
有关汇编说明,请参阅开头提供的视频的汇编部分。
第4步:源代码
github上免费提供源代码:https://github.com/alojzjakob/arduino-color-picker
非常欢迎您改进代码,因为提供的代码只是起点,但效果很好。
这个项目使用这两个特定的库,所以一定要把它们添加到你的arduino ide中:
https://github.com/bearwaterfall/dfrobot_lcd-master/tree/master
https://github.com/dfrobot/dfrobot_tcs34725/raw/master/dfrobot_tcs34725.rar
#include
#include
#define ledpin 12
#define redpin 3
#define greenpin 5
#define bluepin 6
const int8_t button1pin = 7; //1
const int8_t button2pin = 8; //2
const int8_t button3pin = 9; //3
int8_t button1state = 0;
int8_t button2state = 0;
int8_t button3state = 0;
#define activated low
// for a common anode led, connect the common pin to +5v
// for common cathode, connect the common to ground
// set to false if using a common cathode led
#define commonanode true
// our rgb -》 eye-recognized gamma color
byte gammatable[256];
dfrobot_lcd lcd(16,2);
dfrobot_tcs34725 tcs = dfrobot_tcs34725(0x50, tcs34725_gain_60x);
bool ledenabled=false;
int lightsmode=0;
// make some custom characters:
byte light_on[8] = {
0b00100,
0b00100,
0b01110,
0b11111,
0b11111,
0b01110,
0b00000,
0b10101
};
byte light_off[8] = {
0b00100,
0b00100,
0b01110,
0b10001,
0b10001,
0b01110,
0b00000,
0b00000
};
byte rgb_on[8] = {
0b00000,
0b10101,
0b00000,
0b01110,
0b01110,
0b01110,
0b11111,
0b11111
};
byte rgb_off[8] = {
0b00000,
0b00000,
0b00000,
0b01110,
0b01010,
0b01010,
0b10001,
0b11111
};
void setup() {
lcd.init();
// create a new character
lcd.customsymbol(0, light_on);
lcd.customsymbol(1, light_off);
lcd.customsymbol(2, rgb_on);
lcd.customsymbol(3, rgb_off);
pinmode(ledpin, output);
digitalwrite(ledpin, low);
pinmode(button1pin, input);
pinmode(button2pin, input);
pinmode(button3pin, input);
digitalwrite(button1pin, high);
digitalwrite(button2pin, high);
digitalwrite(button3pin, high);
pinmode(redpin, output);
pinmode(greenpin, output);
pinmode(bluepin, output);
analogwrite(redpin,0);
analogwrite(greenpin,0);
analogwrite(bluepin,0);
// thanks philb for this gamma table! it helps convert rgb colors to what humans see
for (int i=0; i《256; i++) {
float x = i;
x /= 255;
x = pow(x, 2.5);
x *= 255;
if (commonanode) {
gammatable[i] = 255 - x;
} else {
gammatable[i] = x;
}
}
}
void loop() {
button1state = digitalread(button1pin);
button2state = digitalread(button2pin);
button3state = digitalread(button3pin);
int btn=0;
if(button1state==low){
btn=1;
}
if(button2state==low){
btn=2;
}
if(button3state==low){
btn=3;
lightsmode++;
if(lightsmode==4){
lightsmode=0;
}
}
uint16_t clear, red, green, blue;
tcs.getrgbc(&red, &green, &blue, &clear);
// figure out some basic hex code for visualization
uint32_t sum = clear;
float r, g, b;
r = red; r /= sum;
g = green; g /= sum;
b = blue; b /= sum;
r *= 255; g *= 255; b *= 255;
string redhex,greenhex,bluehex;
redhex = string((int)r, hex);
greenhex = string((int)g, hex);
bluehex = string((int)b, hex);
lcd.setrgb(r,g,b); //set lcd backlight rgb value
lcd.setcursor(0,0); // print values on lcd
lcd.print(“#”); lcd.print(redhex); lcd.print(greenhex); lcd.print(bluehex); lcd.print(“ ”);
lcd.setcursor(0,1);
lcd.print(“rgb(”);
lcd.print((int)r); lcd.print(“,”);
lcd.print((int)g); lcd.print(“,”);
lcd.print((int)b); lcd.print(“) ”);
if(lightsmode==0){
ledenabled=false;
lcd.setcursor(15,0);
lcd.write((unsigned char)1);//light off
lcd.setcursor(14,0);
lcd.write((unsigned char)2);//rgb led on
//set the color of rgb led indicator
analogwrite(redpin, round(gammatable[(int)r]/4));
analogwrite(greenpin, round(gammatable[(int)g]/4));
analogwrite(bluepin, round(gammatable[(int)b]/4));
}
if(lightsmode==1){
ledenabled=true;
lcd.setcursor(15,0);
lcd.write((unsigned char)0);//light on
lcd.setcursor(14,0);
lcd.write((unsigned char)2);//rgb led on
//set the color of rgb led indicator
analogwrite(redpin, round(gammatable[(int)r]/4));
analogwrite(greenpin, round(gammatable[(int)g]/4));
analogwrite(bluepin, round(gammatable[(int)b]/4));
}
if(lightsmode==2){
ledenabled=true;
lcd.setcursor(15,0);
lcd.write((unsigned char)0);//light on
lcd.setcursor(14,0);
lcd.write((unsigned char)3);//rgb led off
//set the color of rgb led indicator
analogwrite(redpin, 255);
analogwrite(greenpin, 255);
analogwrite(bluepin, 255);
}
if(lightsmode==3){
ledenabled=false;
lcd.setcursor(15,0);
lcd.write((unsigned char)1);//light off
lcd.setcursor(14,0);
lcd.write((unsigned char)3);//rgb led off
//set the color of rgb led indicator
analogwrite(redpin, 255);
analogwrite(greenpin, 255);
analogwrite(bluepin, 255);
}
if(ledenabled){
digitalwrite(ledpin, high);
}else{
digitalwrite(ledpin, low);
}
//delay(10);
}
第5步:享受您的新工具+改进计划
现在你可以到处选择一些漂亮的颜色:)
高通骁龙865将由台积电代工,采用7nm“N7P”工艺
机器人设计时模仿人的形象 但外表上还是和人类有区别
兼容能源之星—同步整流IC U7710SG
半年不到,波音航班再次失事,737 Max 8真的是一款空中杀手吗?
人工智能如何协助控制疫情
Arduino颜色选择器的制作
学习RTOS该如何选择?µC/OS不是收费软件吗?
一文知道UP/MAKRO程序的调用
低端市场价格大战在即 知名手机厂商的避风港
信步科技SV-33A66嵌入式主板介绍
运算放大器基础知识详解
什么是动物克隆?
IGBT搭乘新能源快车打开增长空间天花板
荣耀9怎么样?荣耀9评测:华为荣耀9与华为P10五大细节大比拼,亲兄弟的对决你选谁?
谈谈电机行业三个值得关注的问题
能源监测物联网管理系统助节能,促增效
中国移动将持续提升云网一体化的能力5G将加速这一进程
客户替代风华色环电感时所面临的顾虑
基于FPGA的IPV6数字包的分离与封装的实现
数据显示苹果iOS14升级率高达72%