Electoral-Vote-O-Meter 2012

by 68000 on Tue Nov 06, 2012 6:34 pm

I recently installed 278 RGB LEDs on the exterior of our house. 204 above the garage door and 72 above the front door. I choose the digital individually addressable LPD8806 type strip from adafruit. Right now, it's controlled by a USB BoArduino on a breadboard powered by a lab power supply.

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);
  }
}
Adam Renie
User avatar
68000
 
Posts: 9
Joined: Mon Nov 08, 2010 10:13 am
Location: Fort Wayne, Indiana, USA

Re: Electoral-Vote-O-Meter 2012

by 68000 on Tue Nov 06, 2012 6:48 pm

A few videos of previous LPD8806 work:
http://www.youtube.com/watch?v=l5__5cZkvwU
http://www.youtube.com/watch?v=Gxfd0_GGPPg
http://www.youtube.com/watch?v=wIy75K-rkRI

And I've attached a few pictures of the Electoral-Vote-O-Meter:
24 LED strip test
24 LED strip.JPG
24 LED strip.JPG (179.16 KiB) Viewed 1282 times

204 LED strip above garage
204 LED strip.JPG
204 LED strip.JPG (172.68 KiB) Viewed 1282 times

serial interface
serial interface.png
serial interface.png (50.8 KiB) Viewed 1282 times


A friend just informed me that that Empire State Building had a similar idea this year.
User avatar
68000
 
Posts: 9
Joined: Mon Nov 08, 2010 10:13 am
Location: Fort Wayne, Indiana, USA

Re: Electoral-Vote-O-Meter 2012

by 68000 on Tue Nov 06, 2012 9:36 pm

Recent results:
123_153.JPG
123_153.JPG (138.21 KiB) Viewed 1267 times
Adam Renie
User avatar
68000
 
Posts: 9
Joined: Mon Nov 08, 2010 10:13 am
Location: Fort Wayne, Indiana, USA

Re: Electoral-Vote-O-Meter 2012

by 68000 on Tue Nov 06, 2012 11:39 pm

The LEDs don't lie!
http://www.youtube.com/watch?v=xRhIy9aJIr8
Luckily I have 4 years to come up with a fancier "win" pattern!
Adam Renie
User avatar
68000
 
Posts: 9
Joined: Mon Nov 08, 2010 10:13 am
Location: Fort Wayne, Indiana, USA

Re: Electoral-Vote-O-Meter 2012

by macegr on Mon Dec 03, 2012 3:51 pm

I made something similar to put over my TV during the election. There is a small computer next to my TV, so I modified Eric Gradman's election scraper code from last year to grab the result in realtime.

Image

Image

Code: Select all | TOGGLE FULL SIZE
import urllib2                                                                                 
import serial
import yaml

class ABC(object):
  def __init__(self):
    self.url = 'http://a.abcnews.com/js/elections/2012/general/prod/elections/national/PresidentMap.js'

  def get(self):
    u = urllib2.urlopen(self.url)
    content = "".join(u.readlines()[2:7])
    content = "{\n" + content[:-3].replace(":", ": ") + "}\n}"
    data = yaml.load(content.replace("\t", ""))
    dvotes = data['AllRaceStates']['obamaEV']
    rvotes = data['AllRaceStates']['romneyEV']
    return "[" + rvotes + "," + dvotes + "]"

if __name__=='__main__':
  abc = ABC()
  s=str(abc.get())
  ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
  ser.write(s)
  ser.close()
  print s
macetech LLC - http://www.macetech.com
User avatar
macegr
 
Posts: 288
Joined: Fri Apr 04, 2008 3:46 pm

Re: Electoral-Vote-O-Meter 2012

by 68000 on Mon Dec 03, 2012 8:54 pm

Nicely done macegr! Did you design the hardware as well? What driver IC does it use?
Adam Renie
User avatar
68000
 
Posts: 9
Joined: Mon Nov 08, 2010 10:13 am
Location: Fort Wayne, Indiana, USA

Re: Electoral-Vote-O-Meter 2012

by macegr on Mon Dec 03, 2012 10:38 pm

That's my OctoBrite CYANEA using the TLC5947. Not flexible...or cost effective for house-sized application, haha!
macetech LLC - http://www.macetech.com
User avatar
macegr
 
Posts: 288
Joined: Fri Apr 04, 2008 3:46 pm

Re: Electoral-Vote-O-Meter 2012

by 68000 on Tue Dec 04, 2012 12:42 am

Oh yeah, macetech, I have two of your chronodots! I'm a sucker for all things LED, so I may have to pick up an OctoBrite too.
Adam Renie
User avatar
68000
 
Posts: 9
Joined: Mon Nov 08, 2010 10:13 am
Location: Fort Wayne, Indiana, USA

Re: Electoral-Vote-O-Meter 2012

by aomalley on Tue Dec 04, 2012 1:51 pm

Very cool! For weatherproofing I assume you're just using the plastic shell the strips come in?
Electronic art/tech/music blog: http://www.technoetc.net/blog
aomalley
 
Posts: 12
Joined: Wed Oct 06, 2010 11:38 am
Location: Ottawa, ON, CA

Re: Electoral-Vote-O-Meter 2012

by 68000 on Tue Dec 04, 2012 11:38 pm

I'm just using the waterproof sheathing that came with it for now. I just used electrical tape in attempt to seal off ends and joints. I plan on getting some clear heat shrink tubing and using that throughout instead for a better seal. I really wish it had an adhesive strip on the back and the weatherproof coating like the cool/warm white strips available at Adafruit.

Initially I wanted to use 3M Command Strips to adhere it to the house temporarily because at the time I didn't have the materials to change out the sheathing. Unfortunately they weren't adhering at all in the colder weather. I used a piece of outdoor foam tape every 10 LEDs on the backside to adhere it to the house. It's been holding for over month now. Eventually this will be upgraded to continuous adhesive along the entire strip. The trick is to make sure your surfaces are super-clean. The plastic sheathing attracts dust and dirt.
Adam Renie
User avatar
68000
 
Posts: 9
Joined: Mon Nov 08, 2010 10:13 am
Location: Fort Wayne, Indiana, USA