Skip to content

Commit 6623f4b

Browse files
committed
fadeTo improvement
1 parent ea50ffe commit 6623f4b

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

Twitter_fade_lamp/Twitter_fade_lamp.ino

+40-36
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#include "structRgb.h"
44
#include <avr/pgmspace.h>
55

6-
char *queryString1 = "#Champions";
6+
char *queryString1 = "#news";
77
char *queryString2 = "#arduino";
88

99
char ssid[] = "OFFICINE ARDUINO"; // your network SSID (name)
10-
char pass[] = "T3mporary!"; // your network password (use for WPA, or use as key for WEP)
10+
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
1111
int keyIndex = 0; // your network key Index number (needed only for WEP)
1212
int status = WL_IDLE_STATUS; // status of the wifi connection
1313

@@ -66,7 +66,7 @@ int
6666
unidecode(byte),
6767
timedRead(void);
6868
void
69-
pippo(rgb, rgb);
69+
fadeTo(rgb, rgb);
7070

7171
// ---------------------------------------------------------------------------
7272

@@ -146,6 +146,7 @@ void loop() {
146146
lampShades[i].green = i*15;
147147
lampShades[i].blue = 0;
148148

149+
// Loaded colors
149150
Serial.print(i);
150151
Serial.print(": ");
151152
Serial.print(lampShades[i].red);
@@ -168,6 +169,7 @@ void loop() {
168169
lampShades[i].green = i*15;
169170
lampShades[i].blue = 255;
170171

172+
// Loaded colors
171173
Serial.print(i);
172174
Serial.print(": ");
173175
Serial.print(lampShades[i].red);
@@ -322,7 +324,7 @@ boolean jsonParse(int depth, byte endChar) {
322324

323325
uint8_t cc = (colorCount+1)%8;
324326

325-
pippo(lampShades[colorCount], lampShades[cc]);
327+
fadeTo(lampShades[colorCount], lampShades[cc]);
326328

327329
colorCount = cc;
328330

@@ -445,10 +447,13 @@ void printWifiStatus() {
445447
Serial.println(F(" dBm"));
446448
}
447449

448-
void pippo(rgb in, rgb out) {
450+
void fadeTo(rgb in, rgb out) {
449451
boolean stop_r, stop_g, stop_b;
450452
stop_r = stop_g = stop_b = false;
451453

454+
// use for debugging purposes, this is
455+
// very noisy otherwise ... too much info
456+
/*
452457
Serial.print(in.red);
453458
Serial.print(" ");
454459
Serial.print(in.green);
@@ -462,52 +467,57 @@ void pippo(rgb in, rgb out) {
462467
Serial.print(out.green);
463468
Serial.print(" ");
464469
Serial.println(out.blue);
470+
*/
465471

466472
while(!(stop_r & stop_g & stop_b)) {
467-
// operate each color: RED
468-
469-
if(in.red > 0 && in.red < out.red && out.red <= 255) {
470-
stop_r = false;
473+
474+
if(in.red < out.red) {
471475
in.red++;
476+
stop_r = false;
477+
if(in.red > 255) { in.red = 255; stop_r = true; }
472478
}
473-
if(in.red <= 255 && in.red >out.red && out.red > 0){
479+
if(in.red > out.red) {
474480
in.red--;
475-
stop_r = true;
481+
stop_r = false;
482+
if(in.red < 0) { in.red = 0; stop_r = true; }
476483
}
477-
478-
if(in.green < out.green){
479-
stop_g = false;
484+
if(in.red == out.red) stop_r = true;
485+
486+
if(in.green < out.green) {
480487
in.green++;
488+
stop_g = false;
489+
if(in.green > 255) { in.green = 255; stop_r = true; }
481490
}
482-
if(in.green >= out.green) {
483-
in.green=out.green;
484-
stop_g = true;
491+
if(in.green > out.green) {
492+
in.green--;
493+
stop_g = false;
494+
if(in.green < 0) { in.green = 0; stop_r = true; }
485495
}
486-
487-
if(in.blue < out.blue){
488-
stop_b = false;
496+
if(in.green == out.green) stop_g = true;
497+
498+
if(in.blue < out.blue) {
489499
in.blue++;
500+
stop_b = false;
501+
if(in.blue > 255) { in.blue = 255; stop_r = true; }
490502
}
491-
if(in.blue >= out.blue) {
492-
in.blue=out.blue;
493-
stop_b = true;
503+
if(in.blue > out.blue) {
504+
in.blue--;
505+
stop_b = false;
506+
if(in.blue < 0) { in.blue = 0; stop_r = true; }
494507
}
495-
508+
if(in.blue == out.blue) stop_b = true;
496509

497-
Serial.print(stop_r);
498-
Serial.print(stop_g);
499-
Serial.println(stop_b);
500-
Serial.println((stop_r | stop_g | stop_b));
510+
501511
// use for debugging purposes, this is
502512
// very noisy otherwise ... too much info
503-
513+
/*
504514
Serial.print("R: ");
505515
Serial.print(in.red);
506516
Serial.print(" - G: ");
507517
Serial.print(in.green);
508518
Serial.print(" - B: ");
509519
Serial.println(in.blue);
510-
520+
*/
511521

512522
// push out the colors
513523
analogWrite(pin_r, in.red);
@@ -518,9 +528,3 @@ void pippo(rgb in, rgb out) {
518528
}
519529

520530
}
521-
522-
int freeRam () {
523-
extern int __heap_start, *__brkval;
524-
int v;
525-
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
526-
}

0 commit comments

Comments
 (0)