步驟1:零件清單
對(duì)于此項(xiàng)目,我們需要:
TCS34725 RGB顏色傳感器對(duì)于Arduino by DFRobot
帶有RGB字體顯示的I2C 16x2 Arduino LCD DFRobot
DFRobino的DFRduino Pro Mini V1.3(8M3.3V328)
2 x CR2032電池座
滑動(dòng)開(kāi)關(guān)
RGB LED模塊
電線
3x7 cm原型PCB
男性和母針頭
2x M2x20螺絲和螺母
工具:
3D打印機(jī),如果你不擁有它,你可以從Shapeways獲得印花盒
菲利普斯螺絲刀
烙鐵
焊接
步驟2:原理圖
請(qǐng)參閱下面打開(kāi)視頻的裝配部分和示意圖,了解如何
使用上面提供的原理圖進(jìn)行正確接線。
2》
在測(cè)量完零件后,是時(shí)候設(shè)計(jì)一個(gè)3D外殼并進(jìn)行打印了!
設(shè)計(jì)
以下是我在tinkercad上的設(shè)計(jì)鏈接:https://www.tinkercad.com/things/dG47Pr28uwx
上面的內(nèi)容設(shè)計(jì)非常適合上面列出的所有組件。
前部將固定LCD屏幕和顏色傳感器。
主要的3x7 cm PCB將容納DFRDuino Pro Mini,電池座和3個(gè)按鈕,將是從內(nèi)部擰到后部。
RGB LED將位于后部頂部?jī)?nèi)部。
電源開(kāi)關(guān)將安裝在后部的小孔中。
打印
準(zhǔn)備打印的3D模型是av適用于Thingiverse:https://www.thingiverse.com/thing:3223709
打印設(shè)置可能因打印機(jī)而異。
電池蓋部件和前部需要支撐因?yàn)榍安坑幸粋€(gè)內(nèi)置的距離,可以提供顏色傳感器和樣品之間的距離。
如果你沒(méi)有3D打印機(jī),你可以從Shapeways獲得印刷品:點(diǎn)擊這里
有關(guān)匯編說(shuō)明,請(qǐng)參閱開(kāi)頭提供的視頻的匯編部分。
第4步:源代碼
GitHub上免費(fèi)提供源代碼:https://github.com/alojzjakob/Arduino-Color-Picker
非常歡迎您改進(jìn)代碼,因?yàn)樘峁┑拇a只是起點(diǎn),但效果很好。
這個(gè)項(xiàng)目使用這兩個(gè)特定的庫(kù),所以一定要把它們添加到你的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步:享受您的新工具+改進(jìn)計(jì)劃
現(xiàn)在你可以到處選擇一些漂亮的顏色:)
-
Arduino
+關(guān)注
關(guān)注
187文章
6458瀏覽量
186504
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論