I already made simple programs for for our son's first birthday and Halloween. I had to put this investment to good use on election day too. I wrote a quick program that allows you increment or decrement the electoral vote results over the serial port. There is currently no support for independent votes, but there is also a simple pattern for the winner.
I normally would go into more details, but I'd like to share this code in case anyone else wants to follow along...
- Code: Select all | TOGGLE FULL SIZE
#include "LPD8806.h"
#include "SPI.h"
#define LENGTH 204
#define BRIGHTNESS 127
#define ELECTORS 538
int dataPin = 11;
int clockPin = 13;
LPD8806 strip = LPD8806(LENGTH, dataPin, clockPin); // software mode
//LPD8806 strip = LPD8806(LENGTH); // hardware mode
long i;
long j;
long left;
long right;
long input;
void setup()
{
strip.begin();
strip.show();
Serial.begin(9600);
j = 0;
left = 0;
right = 0;
}
void loop()
{
for (i = 0; i < LENGTH; i++)
{
if (left >= (ELECTORS / 2))
{
if (((i * ELECTORS) / LENGTH) < left)
{
strip.setPixelColor(i, strip.Color(0, 0, j % BRIGHTNESS));
}
else if (((i * ELECTORS) / LENGTH) >= (ELECTORS - right))
{
strip.setPixelColor(i, strip.Color(BRIGHTNESS / 4, 0, 0));
}
else
{
strip.setPixelColor(i, strip.Color(0, 0, 0));
}
if ((i == ((LENGTH - 1) / 2)) || (i == (LENGTH / 2)))
{
strip.setPixelColor(i, strip.Color((j % BRIGHTNESS) / 2, (j % BRIGHTNESS) / 2, BRIGHTNESS));
}
}
else if (right >= (ELECTORS / 2))
{
if (((i * ELECTORS) / LENGTH) < left)
{
strip.setPixelColor(i, strip.Color(0, 0, BRIGHTNESS / 4));
}
else if (((i * ELECTORS) / LENGTH) >= (ELECTORS - right))
{
strip.setPixelColor(i, strip.Color(j % BRIGHTNESS, 0, 0));
}
else
{
strip.setPixelColor(i, strip.Color(0, 0, 0));
}
if ((i == ((LENGTH - 1) / 2)) || (i == (LENGTH / 2)))
{
strip.setPixelColor(i, strip.Color(BRIGHTNESS, (j % BRIGHTNESS) / 2, (j % BRIGHTNESS) / 2));
}
}
else
{
if (((i * ELECTORS) / LENGTH) < left)
{
strip.setPixelColor(i, strip.Color(0, 0, BRIGHTNESS));
}
else if (((i * ELECTORS) / LENGTH) >= (ELECTORS - right))
{
strip.setPixelColor(i, strip.Color(BRIGHTNESS, 0, 0));
}
else
{
strip.setPixelColor(i, strip.Color(0, 0, 0));
}
if ((i == ((LENGTH - 1) / 2)) || (i == (LENGTH / 2)))
{
strip.setPixelColor(i, strip.Color(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS));
}
}
}
delay(20);
j++;
if (j >= BRIGHTNESS)
{
j = 0;
}
strip.show();
if (Serial.available() > 0)
{
input = Serial.read();
if (input == 'd')
{
left--;
}
if (input == 'D')
{
left++;
}
if (input == 'c')
{
left -= 10;
}
if (input == 'C')
{
left += 10;
}
if (input == 'r')
{
right--;
}
if (input == 'R')
{
right++;
}
if (input == 'f')
{
right -= 10;
}
if (input == 'F')
{
right += 10;
}
Serial.print("Democrat: ");
Serial.print(left);
Serial.print(", Republican: ");
Serial.print(right);
Serial.print(", Undecided: ");
Serial.println(ELECTORS - left - right);
}
}