Devices & Components
Arduino Mini
wood panel
Capteurs de couleur ADA1334
Wood Glue
Hardware & Tools
Soldering kit
laser sheet cutting machine
Software & Tools
Processing 3
Arduino IDE
Project description
Code
Arduino code
actionscript
Arduino code
1#include <Wire.h> 2#include "Adafruit_TCS34725.h" 3 4 5 6 7 8byte gammatable[256]; 9Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); 10 11 12 13 14 15// Pick analog outputs, for the UNO these three work well 16// use ~560 ohm resistor between Red & Blue, ~1K for green (its brighter) 17 18// for a common anode LED, connect the common pin to +5V 19// for common cathode, connect the common to ground 20 21// set to false if using a common cathode LED 22 23 24// our RGB -> eye-recognized gamma color 25 26 27 28void setup() { 29 Serial.begin(9600); 30 // Serial.println("Color View Test!"); 31 32 if (tcs.begin()) { 33 Serial.println("Found"); 34 } else { 35 Serial.println("No TCS34725 found ... check your connections"); 36 while (1); // halt! 37 } 38 39 // use these three pins to drive an LED pinMode(redpin, OUTPUT); pinMode(greenpin, OUTPUT); 40 41 // thanks PhilB for this gamma table! 42 // it helps convert RGB colors to what humans see 43 for (int i=0; i<256; i++) { 44 float x = i; 45 x /= 255; 46 x = pow(x, 2.5); 47 x *= 255; 48 49 50 //Serial.println(gammatable[i]); 51 } 52} 53 54 55void loop() { 56 57 uint16_t clear, red, green, blue; 58 59 tcs.setInterrupt(false); // turn on LED 60 61 delay(60); // takes 50ms to read 62 63 tcs.getRawData(&red, &green, &blue, &clear); 64 65 tcs.setInterrupt(true); // turn off LED 66 67 68 69 // Figure out some basic hex code for visualization 70 uint32_t sum = clear; 71 float r, g, b; 72 r = red; r /= sum; 73 g = green; g /= sum; 74 b = blue; b /= sum; 75 r *= 256; g *= 256; b *= 256; 76 77 78 Serial.print((int)r ); Serial.print("L"); Serial.print((int)g);Serial.print("L"); Serial.println((int)b ); 79}
Processing code
processing
Code for changing colors
1import processing.serial.*; 2 Serial port; 3 //int rgb[] = {0,1,2}; 4float result[] = {0,1,2,3}; 5 int rgb[]={0,1,2,3}; 6//private int program = 25; 7int rrr; 8int ggg; 9int bbb; 10 11 12float x,y; 13 14//int n = 100; 15//float [] xdata = new float[n]; 16 17void setup() { 18 //background(100,200,200); 19 size (600, 600); 20 //background (127); 21 22 println(Serial.list()); 23 port = new Serial(this, Serial.list()[18], 9600); 24 port.bufferUntil('\n'); // don't generate a serialEvent() unless you get a 25 26 27 28 29} 30 31void draw(){ 32 background (rrr,ggg,bbb); 33fill(20,20,20); 34 35 36 noStroke(); 37} 38void serialEvent(Serial port) { 39 40 String inString = port.readStringUntil('\n'); 41 // println(inString); 42 //if (inString=="Found sensor"){ 43 int longu= inString.length(); 44 println (inString); 45print("longu=");println(longu); 46if (longu==11||longu==12||longu==13){ 47 float[] result = float(split(inString, 'L')); 48 49 50 println (result[0]); 51 println (result[1]); 52println (result[2]); 53 54 rrr= (int)result[0]; 55 print (rrr); 56 ggg= (int)result[1]; 57 bbb= (int)result[2]; 58 fill(20,20,20); 59ellipse(100,100,100,100); 60 61 //for (int i=1;i<4;i++){ 62//rgb[i] =(int)(result[i]); 63 64 } 65}
Downloadable files
File for cute
File for cutting laser box
File for cute.pdf
Comments
Only logged in users can leave comments