/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include <avr/pgmspace.h>
-#include "gamma.h"
-
+#define DITHER_BITS 1
+const int led_color_max = pow (2, 16) - 1;
const int dither_steps = pow (2, DITHER_BITS);
typedef struct rgb_pins
const int rgb_banks = 2;
-const rgb_pins pins[rgb_banks] = { {10, 9, 11},
- {5, 6, 3} };
-
-static int led_colors[rgb_banks * 3];
+//const rgb_pins pins[rgb_banks] = { {10, 9, 11},
+// {5, 6, 3} };
+const rgb_pins pins[rgb_banks] = { {9, 6, 10},
+ {4, 5, 3} };
void set_color_x (int r, int g, int b, int dither_step = 0)
{
for (int bank = 0; bank < rgb_banks; bank++)
{
- analogWrite (pins[bank].red, pgm_read_byte_near (gammaTable + (r >= 0 ? offset : 0) + r));
- analogWrite (pins[bank].green, pgm_read_byte_near (gammaTable + (g >= 0 ? offset : 0) + g));
- analogWrite (pins[bank].blue, pgm_read_byte_near (gammaTable + (b >= 0 ? offset : 0) + b));
+ analogWrite (pins[bank].red, r);
+ analogWrite (pins[bank].green, g);
+ analogWrite (pins[bank].blue, b);
}
}
void setup ()
{
Serial.begin (115200);
- Serial.setTimeout (100000);
+ Serial.setTimeout (20000);
+ analogWriteResolution (16);
+ randomSeed (analogRead (14));
for (int bank = 0; bank < rgb_banks; bank++)
{
}
// Test sequence to confirm wiring
- set_color_x (255, 255, 255);
+ set_color_x (led_color_max, led_color_max, led_color_max);
delay(500);
- set_color_x (255, 0, 0);
+ set_color_x (led_color_max, 0, 0);
delay (500);
- set_color_x (0, 255, 0);
+ set_color_x (0, led_color_max, 0);
delay (500);
- set_color_x (0, 0, 255);
+ set_color_x (0, 0, led_color_max);
delay (500);
}
void loop ()
{
- static int r = 192;
- static int g = 192;
- static int b = 192;
+ static int r = led_color_max / 2;
+ static int g = led_color_max / 2;
+ static int b = led_color_max / 2;
static int step = -1;
//step = (step + 1) % dither_steps;
step = 0; // dithering is bogus/i'm-not-doing-it-right
- if (Serial.available () >= 3)
+ if (Serial.available ())
{
- r = Serial.read ();
- g = Serial.read ();
- b = Serial.read ();
+ r = Serial.parseInt ();
+ g = Serial.parseInt ();
+ b = Serial.parseInt ();
Serial.print ("set color ");
Serial.print (r);
set_color_x (r, g, b);
}
+ // display random colors when the serial port is closed
+ if (!Serial.dtr ())
+ {
+ set_color_x (random (led_color_max), random (led_color_max), random (led_color_max));
+ delay (1500);
+ }
+
set_color_x (r, g, b, step);
}