make acrylic art code actually work (using tinkercad, parts not in yet)
parent
a404925725
commit
b328a4b00e
@ -1,21 +1,108 @@
|
||||
#include <FastLED.h>
|
||||
int light = 0;
|
||||
int r = 9;
|
||||
int g = 10;
|
||||
int b = 11;
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int ss = 30; // sample size for light sensor
|
||||
int ss = 100; // sample size for light sensor
|
||||
int average = 0;
|
||||
for (int x = 0; x < ss; x++) {
|
||||
average += analogRead(light);
|
||||
delay(1);
|
||||
average += analogRead(light) / 4;
|
||||
delay(3);
|
||||
}
|
||||
average /= ss;
|
||||
String bitIn = "";
|
||||
for(int x = 0; x <9; x++) {
|
||||
bitIn += average >> x;
|
||||
}
|
||||
int a = bitIn.substring(0, 3).toInt();
|
||||
int b = bitIn.substring(3, 6).toInt();
|
||||
int c = bitIn.substring(6, 9).toInt();
|
||||
// set LED strips to c, b, a (in order RGB)
|
||||
CRGB color = CHSV(average, 255, 255);
|
||||
analogWrite(9, color.r);
|
||||
analogWrite(10, color.g);
|
||||
analogWrite(11, color.b);
|
||||
Serial.print("Hue: ");
|
||||
Serial.print(average);
|
||||
Serial.print(", RGB : ");
|
||||
Serial.print(color.r);
|
||||
Serial.print(", ");
|
||||
Serial.print(color.g);
|
||||
Serial.print(", ");
|
||||
Serial.println(color.b);
|
||||
}
|
||||
/* Library free version for regular RGB LEDs (tinkercad), using HSV --> RGB code not by me
|
||||
//#include <FastLED.h>
|
||||
int light = 0;
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int ss = 20; // sample size for light sensor
|
||||
int average = 0;
|
||||
for (int x = 0; x < ss; x++) {
|
||||
average += analogRead(light) / 4;
|
||||
delay(3);
|
||||
}
|
||||
average /= ss;
|
||||
byte RedLight;
|
||||
byte GreenLight;
|
||||
byte BlueLight;
|
||||
|
||||
// this is the algorithm to convert from RGB to HSV
|
||||
byte h = average;
|
||||
byte s = 255;
|
||||
byte v = 60;
|
||||
h = (h * 192) / 256; // 0..191
|
||||
unsigned int i = h / 32; // We want a value of 0 thru 5
|
||||
unsigned int f = (h % 32) * 8; // 'fractional' part of 'i' 0..248 in jumps
|
||||
|
||||
unsigned int sInv = 255 - s; // 0 -> 0xff, 0xff -> 0
|
||||
unsigned int fInv = 255 - f; // 0 -> 0xff, 0xff -> 0
|
||||
byte pv = v * sInv / 256; // pv will be in range 0 - 255
|
||||
byte qv = v * (256 - s * f / 256) / 256;
|
||||
byte tv = v * (256 - s * fInv / 256) / 256;
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
RedLight = v;
|
||||
GreenLight = tv;
|
||||
BlueLight = pv;
|
||||
break;
|
||||
case 1:
|
||||
RedLight = qv;
|
||||
GreenLight = v;
|
||||
BlueLight = pv;
|
||||
break;
|
||||
case 2:
|
||||
RedLight = pv;
|
||||
GreenLight = v;
|
||||
BlueLight = tv;
|
||||
break;
|
||||
case 3:
|
||||
RedLight = pv;
|
||||
GreenLight = qv;
|
||||
BlueLight = v;
|
||||
break;
|
||||
case 4:
|
||||
RedLight = tv;
|
||||
GreenLight = pv;
|
||||
BlueLight = v;
|
||||
break;
|
||||
case 5:
|
||||
RedLight = v;
|
||||
GreenLight = pv;
|
||||
BlueLight = qv;
|
||||
break;
|
||||
}
|
||||
//CRGB& color = CHSV(average, 255, 255);
|
||||
Serial.print("Hue: ");
|
||||
Serial.print(average);
|
||||
Serial.print(", RGB : ");
|
||||
Serial.print(RedLight);
|
||||
Serial.print(", ");
|
||||
Serial.print(GreenLight);
|
||||
Serial.print(", ");
|
||||
Serial.println(BlueLight);
|
||||
analogWrite(9, RedLight);
|
||||
analogWrite(10, GreenLight);
|
||||
analogWrite(11, BlueLight);
|
||||
}*/
|
||||
|
Loading…
Reference in New Issue