|
|
@ -1,8 +1,9 @@
|
|
|
|
#include <FastLED.h>
|
|
|
|
#include <FastLED.h>
|
|
|
|
int light = 0;
|
|
|
|
int light = 0;
|
|
|
|
int r = 9;
|
|
|
|
int r = 9; // define pins
|
|
|
|
int g = 10;
|
|
|
|
int g = 10;
|
|
|
|
int b = 11;
|
|
|
|
int b = 11;
|
|
|
|
|
|
|
|
int oldavg = 0;
|
|
|
|
void setup() {
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
|
|
|
Serial.begin(9600);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -15,12 +16,32 @@ void loop() {
|
|
|
|
delay(3);
|
|
|
|
delay(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
average /= ss;
|
|
|
|
average /= ss;
|
|
|
|
CRGB color = CHSV(average, 255, 255);
|
|
|
|
if (oldavg == 0) {
|
|
|
|
|
|
|
|
oldavg = average;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
digitalWrite(13, HIGH);
|
|
|
|
|
|
|
|
if (oldavg != average) {
|
|
|
|
|
|
|
|
Serial.print("Goal: ");
|
|
|
|
|
|
|
|
Serial.println(average);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while (oldavg < average) {
|
|
|
|
|
|
|
|
oldavg ++;
|
|
|
|
|
|
|
|
setColor(oldavg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while (oldavg > average) {
|
|
|
|
|
|
|
|
oldavg --;
|
|
|
|
|
|
|
|
setColor(oldavg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
digitalWrite(13, LOW);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setColor(int hue) {
|
|
|
|
|
|
|
|
CRGB color = CHSV(hue, 255, 255);
|
|
|
|
analogWrite(9, color.r);
|
|
|
|
analogWrite(9, color.r);
|
|
|
|
analogWrite(10, color.g);
|
|
|
|
analogWrite(10, color.g);
|
|
|
|
analogWrite(11, color.b);
|
|
|
|
analogWrite(11, color.b);
|
|
|
|
Serial.print("Hue: ");
|
|
|
|
Serial.print("Hue: ");
|
|
|
|
Serial.print(average);
|
|
|
|
Serial.print(hue);
|
|
|
|
Serial.print(", RGB : ");
|
|
|
|
Serial.print(", RGB : ");
|
|
|
|
Serial.print(color.r);
|
|
|
|
Serial.print(color.r);
|
|
|
|
Serial.print(", ");
|
|
|
|
Serial.print(", ");
|
|
|
@ -29,13 +50,16 @@ void loop() {
|
|
|
|
Serial.println(color.b);
|
|
|
|
Serial.println(color.b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// END OF CODE
|
|
|
|
// END OF CODE
|
|
|
|
|
|
|
|
|
|
|
|
/* Library free version for regular RGB LEDs (tinkercad), using HSV --> RGB code not by me
|
|
|
|
|
|
|
|
|
|
|
|
/*// Library free version for regular RGB LEDs (tinkercad), using HSV --> RGB code not by me
|
|
|
|
//#include <FastLED.h>
|
|
|
|
//#include <FastLED.h>
|
|
|
|
int light = 0;
|
|
|
|
int light = 0;
|
|
|
|
|
|
|
|
int oldavg = 0;
|
|
|
|
void setup() {
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
|
|
|
Serial.begin(9600);
|
|
|
|
|
|
|
|
pinMode(13, OUTPUT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
void loop() {
|
|
|
@ -46,15 +70,34 @@ void loop() {
|
|
|
|
delay(3);
|
|
|
|
delay(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
average /= ss;
|
|
|
|
average /= ss;
|
|
|
|
|
|
|
|
if(oldavg == 0) {
|
|
|
|
|
|
|
|
oldavg = average;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
digitalWrite(13, HIGH);
|
|
|
|
|
|
|
|
if(oldavg != average) {
|
|
|
|
|
|
|
|
Serial.print("Goal: ");
|
|
|
|
|
|
|
|
Serial.println(average);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while(oldavg < average) {
|
|
|
|
|
|
|
|
oldavg ++;
|
|
|
|
|
|
|
|
setColor(oldavg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while(oldavg > average) {
|
|
|
|
|
|
|
|
oldavg --;
|
|
|
|
|
|
|
|
setColor(oldavg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
digitalWrite(13, LOW);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetColor(int hue) {
|
|
|
|
byte RedLight;
|
|
|
|
byte RedLight;
|
|
|
|
byte GreenLight;
|
|
|
|
byte GreenLight;
|
|
|
|
byte BlueLight;
|
|
|
|
byte BlueLight;
|
|
|
|
|
|
|
|
|
|
|
|
// this is the algorithm to convert from RGB to HSV
|
|
|
|
// this is the algorithm to convert from RGB to HSV
|
|
|
|
byte h = average;
|
|
|
|
byte h = hue;
|
|
|
|
byte s = 255;
|
|
|
|
byte s = 255;
|
|
|
|
byte v = 60;
|
|
|
|
byte v = 60;
|
|
|
|
h = (h * 192) / 256; // 0..191
|
|
|
|
h = (h * 192) / 256; // ..191
|
|
|
|
unsigned int i = h / 32; // We want a value of 0 thru 5
|
|
|
|
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 f = (h % 32) * 8; // 'fractional' part of 'i' 0..248 in jumps
|
|
|
|
|
|
|
|
|
|
|
@ -98,7 +141,7 @@ byte BlueLight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//CRGB& color = CHSV(average, 255, 255);
|
|
|
|
//CRGB& color = CHSV(average, 255, 255);
|
|
|
|
Serial.print("Hue: ");
|
|
|
|
Serial.print("Hue: ");
|
|
|
|
Serial.print(average);
|
|
|
|
Serial.print(hue);
|
|
|
|
Serial.print(", RGB : ");
|
|
|
|
Serial.print(", RGB : ");
|
|
|
|
Serial.print(RedLight);
|
|
|
|
Serial.print(RedLight);
|
|
|
|
Serial.print(", ");
|
|
|
|
Serial.print(", ");
|
|
|
|