public
Last active

Having a hell of a time with this arduino sketch. It's for this installation: http://www.andrewlb.com/2013/01/firesite-debug-view/ I think I'm getting there though. It is currently not quite working, but kind of working. I had misunderstood how the LPD8806 chip worked, switched over to only using the PWM pins. I'm going to have to split the signals across the different strips somehow, also potentially boost via 74HCT245 IC to get distance. Also, the color mixing for this thing is insane, and not corresponding to the RGB vals I pulled from the LPD8806 lib from adafruit. These aren't the adafruit LED strips though.

  • Download Gist
firesiteSerial.ino
Arduino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
#include "LPD8806.h"
#include "SPI.h"
 
// Constants
const int NUMLIGHTS = 6; // Number of lights per arm
const int NUMARMS = 3; // Number of arms per light
const int LEDPERARM = 20; // Number of lights
const int serialPin = 52;
const int testPin = 53;
bool connected;
 
int dataPins[NUMLIGHTS/**NUMARMS*/] = {
// 22,24,26, // Light 0
// 28,30,32, // Light 1
// 34,36,38, // Light 2
// 40,42,44, // Light 3
// 46,48,50, // Light 4
// 4,6,8 // Light 5
2,
4,
6,
8,
10,
12
};
 
int clockPins[NUMLIGHTS/**NUMARMS*/] = {
// 23,25,27, // Light 0
// 29,31,33, // Light 1
// 35,37,39, // Light 2
// 41,43,45, // Light 3
// 47,49,51, // Light 4
// 5,7,9 // Light 5
3,
5,
7,
9,
11,
13
};
 
// Light struct
typedef struct {
int id; // The id must match that of the OF program
int pwr; // 0-127 val, derived from OF float val
LPD8806 strip[NUMARMS]; // The three strips
} Light;
 
Light Lights[NUMLIGHTS]; // Declare lights array
 
 
// Serial communication
String inString = "";
int curLight = 0;
//int curArm = 0;
int curPwr = 0;
 
void setup() {
// Setup all lights and arms
pinMode(testPin,OUTPUT);
pinMode(serialPin,OUTPUT);
for(int i=0;i<NUMLIGHTS;i++) {
// Set up the Lights with the appropriate objects
Lights[i].id = i;
for(int a=0;a<NUMARMS;a++) {
Lights[i].strip[a] = LPD8806(LEDPERARM, dataPins[i+a], clockPins[i+a]);
Lights[i].strip[a].begin();
Lights[i].strip[a].show();
testStrip(&Lights[i].strip[a]);
clearStrip(&Lights[i].strip[a]);
}
}
// Start serial communication
Serial.begin(9600); connected = false;
digitalWrite(testPin, HIGH);
delay(500);
}
 
void testStrip(LPD8806 * strip) {
int i;
for(i=0; i<strip->numPixels(); i++) {
strip->setPixelColor(i, 0);
}
strip->show();
// Then display one pixel at a time:
for(i=0; i<strip->numPixels(); i++) {
strip->setPixelColor(i, getColor(127) ); // Set new pixel 'on'
strip->show(); // Refresh LED states
strip->setPixelColor(i, 0); // Erase pixel, but don't refresh!
delay(25);
}
strip->show(); // Refresh to turn off last pixel
}
 
void clearStrip(LPD8806 * strip) {
int i;
for (i=0; i < strip->numPixels(); i++) {
strip->setPixelColor(i, getColor(0));
strip->show();
delay(10);
}
}
void loop() {
if(connected) {
digitalWrite(serialPin,HIGH);
digitalWrite(testPin, LOW);
for(int i=0;i<NUMLIGHTS;i++) {
render(i);
}
digitalWrite(testPin, HIGH);
} else {
digitalWrite(serialPin,LOW);
digitalWrite(testPin, HIGH);
for(int i=0;i<NUMLIGHTS;i++) {
//Lights[i].pwr = 127;
// render(i);
for( int a=0;a<NUMARMS;a++) {
testStrip(&Lights[i].strip[a]);
}
}
digitalWrite(testPin, LOW);
}
}
void render(uint32_t lightId) {
int maxPower, minPower, ptr, ledStr, pwr;
for(int a=0;a<NUMARMS;a++) {
// Turn on
for(int i=0;i<LEDPERARM;i++) {
Lights[lightId].strip[a].setPixelColor(i,0);
maxPower = i / LEDPERARM;
minPower = 127 - (maxPower * (127-Lights[lightId].pwr));
// ptr = i + ( a * LEDPERARM );
pwr = Lights[lightId].pwr;
if(pwr > 0)
Lights[lightId].strip[a].setPixelColor(i,getColor(pwr));
// Lights[lightId].strip[a].show();
// Lights[lightId].strip[a].setPixelColor(i,127);
}
Lights[lightId].strip[a].show();
delay(10);
// Turn all off
}
//for(int a=0;a<NUMARMS;a++) {
// for(int i=0;i<LEDPERARM;i++) {
// Lights[lightId].strip[a].setPixelColor(i,0);
// }
// Lights[lightId].strip[a].show();
//}
// holders for 10ms
}
 
// Derived from the LPD8806 lib
uint32_t getColor(int pwr) {
byte r,g,b;
r = (byte)1-(pwr/2);
b = (byte)(pwr/2);
g = (byte)0;
/*
r = 127;
b = 60;
g = 0; */
return ((uint32_t)(g | 0x80) << 16) |
((uint32_t)(r | 0x80) << 8) |
b | 0x80 ;
}
void parseSerial() {
// Read serial input:
int inChar;
while(Serial.available()) {
inChar = Serial.read();
// Collecting the datas.
if (isDigit(inChar)) {
inString += (char)inChar;
}
// Iterating through the lights
if (inChar == ',') {
Lights[curLight].pwr = inString.toInt();
inString = "";
curLight++;
}
// Last light
if (inChar == '\n') {
Lights[NUMLIGHTS-1].pwr = inString.toInt();
inString = "";
curLight = 0;
}
Serial.println(curLight);
Serial.println(Lights[curLight].pwr);
}
}
 
void serialEvent() {
connected = true;
parseSerial();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.