Browse Source

Update 'acrylic-art-code-nolib/acrylic-art-code-nolib.ino'

master
shark 2 years ago
parent
commit
ca66539184
1 changed files with 16 additions and 16 deletions
  1. +16
    -16
      acrylic-art-code-nolib/acrylic-art-code-nolib.ino

+ 16
- 16
acrylic-art-code-nolib/acrylic-art-code-nolib.ino View File

@ -1,4 +1,4 @@
// Library free version for regular RGB LEDs (tinkercad), using HSV --> RGB code not by me
// Library free version, using HSV --> RGB code not by me
//#include < FastLED.h >
int light = 0;
int oldavg = 0;
@ -11,32 +11,32 @@ void loop() {
int ss = 20; // sample size for light sensor
int average = 0;
for (int x = 0; x < ss; x++) {
//average += 256-log(256-analogRead(0) / 4) * (256 /5.55); // old linearization
// linearization using resistance to lux relationship
average += map(1250000.0 * pow(1023-analogRead(0), -1.4059), 73, 339, 0, 128);
// mapping to correct values
average += map(analogRead(0), 0, 1023, 0, 127);
delay(3);
}
average /= ss;
//Serial.println(analogRead(0));
//Serial.println(average);
if (oldavg == 0) {
oldavg = average;
}
digitalWrite(13, HIGH);
if (oldavg != average) {
if (abs(oldavg - average) > 1) {
Serial.print("Goal: ");
Serial.println(average);
digitalWrite(13, HIGH);
while (oldavg < average) {
oldavg += 2;
setColor(oldavg);
}
while (oldavg > average) {
oldavg -= 2;
setColor(oldavg);
}
digitalWrite(13, LOW);
}
while (oldavg < average) {
oldavg += 1;
setColor(oldavg);
}
while (oldavg > average) {
oldavg -= 1;
setColor(oldavg);
}
digitalWrite(13, LOW);
}
void setColor(int hue) {
byte RedLight;
byte GreenLight;


Loading…
Cancel
Save

Proudly self-hosted by Cole Deck. Fast loading powered by Turbo.