public
Last active

Custom Light Controller program for Arduino and relays

  • Download Gist
lambert-flasher-program.pde
Processing
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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
//relay pins
#define relayAPin 2
#define relayBPin 3
#define relayCPin 4
#define relayDPin 5
#define relayEPin 6
#define relayFPin 7
#define relayGPin 8
#define relayHPin 9
 
 
 
//pot pin
#define potPin A5
//lowest change rate in milliseconds
#define lowRate 50
//#define lowRate 125
 
//highest change rate in milliseconds
#define highRate 2000
 
// the length of your pattern (how many stages there are)
// Make sure this is consitant with number of BXXXX things in HGFEDCBA Pattern
#define patternLength 1280
 
//timing
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
 
//flashing
static int currentPattern = 0;
 
//HGFEDCBA Patterns - FUN TO CHANGE!!!
//B"XXXX" for 4 channels
//B"XXXXXXXX" for 8 channels and so on
//Make sure to change the patten length above.
byte pattern[patternLength] = {
//count across med
B1111, B1111, B0111, B0111, B0011, B0011, B0001, B0001,
B0000, B0000, B1000, B1000, B1100, B1100, B1110, B1110,
B1111, B1111, B0111, B0111, B0011, B0011, B0001, B0001,
B0000, B0000, B1000, B1000, B1100, B1100, B1110, B1110,
 
B1111, B1111, B0111, B0111, B0011, B0011, B0001, B0001,
B0000, B0000, B1000, B1000, B1100, B1100, B1110, B1110,
B1111, B1111, B0111, B0111, B0011, B0011, B0001, B0001,
B0000, B0000, B1000, B1000, B1100, B1100, B1110, B1110,
//64
 
// one moves across med
B1000, B1000, B0100, B0100, B0010, B0010, B0001, B0001,
B1000, B1000, B0100, B0100, B0010, B0010, B0001, B0001,
B1000, B1000, B0100, B0100, B0010, B0010, B0001, B0001,
B1000, B1000, B0100, B0100, B0010, B0010, B0001, B0001,
 
B1000, B1000, B0100, B0100, B0010, B0010, B0001, B0001,
B1000, B1000, B0100, B0100, B0010, B0010, B0001, B0001,
B1000, B1000, B0100, B0100, B0010, B0010, B0001, B0001,
B1000, B1000, B0100, B0100, B0010, B0010, B0001, B0001,
//128
 
//one moves across fast
B1000, B0100, B0010, B0001, B1000, B0100, B0010, B0001,
B1000, B0100, B0010, B0001, B1000, B0100, B0010, B0001,
B1000, B0100, B0010, B0001, B1000, B0100, B0010, B0001,
B1000, B0100, B0010, B0001, B1000, B0100, B0010, B0001,
 
B1000, B0100, B0010, B0001, B1000, B0100, B0010, B0001,
B1000, B0100, B0010, B0001, B1000, B0100, B0010, B0001,
B1000, B0100, B0010, B0001, B1000, B0100, B0010, B0001,
B1000, B0100, B0010, B0001, B1000, B0100, B0010, B0001,
//192
 
//count across fast
B1111, B0111, B0011, B0001, B0000, B1000, B1100, B1110,
B1111, B0111, B0011, B0001, B0000, B1000, B1100, B1110,
B1111, B0111, B0011, B0001, B0000, B1000, B1100, B1110,
B1111, B0111, B0011, B0001, B0000, B1000, B1100, B1110,
 
B1111, B0111, B0011, B0001, B0000, B1000, B1100, B1110,
B1111, B0111, B0011, B0001, B0000, B1000, B1100, B1110,
B1111, B0111, B0011, B0001, B0000, B1000, B1100, B1110,
B1111, B0111, B0011, B0001, B0000, B1000, B1100, B1110,
//256
 
//4 slow flash
B1111, B1111, B1111, B1111, B0000, B0000, B0000, B0000,
B1111, B1111, B1111, B1111, B0000, B0000, B0000, B0000,
B1111, B1111, B1111, B1111, B0000, B0000, B0000, B0000,
B1111, B1111, B1111, B1111, B0000, B0000, B0000, B0000,
 
B1111, B1111, B1111, B1111, B0000, B0000, B0000, B0000,
B1111, B1111, B1111, B1111, B0000, B0000, B0000, B0000,
B1111, B1111, B1111, B1111, B0000, B0000, B0000, B0000,
B1111, B1111, B1111, B1111, B0000, B0000, B0000, B0000,
 
// three moves across med
B1110, B1110, B0111, B0111, B1011, B1011, B1101, B1101,
B1110, B1110, B0111, B0111, B1011, B1011, B1101, B1101,
B1110, B1110, B0111, B0111, B1011, B1011, B1101, B1101,
B1110, B1110, B0111, B0111, B1011, B1011, B1101, B1101,
 
B1110, B1110, B0111, B0111, B1011, B1011, B1101, B1101,
B1110, B1110, B0111, B0111, B1011, B1011, B1101, B1101,
B1110, B1110, B0111, B0111, B1011, B1011, B1101, B1101,
B1110, B1110, B0111, B0111, B1011, B1011, B1101, B1101,
 
// winky winky flip flop med
B1100, B1100, B1111, B1111, B0011, B0011, B0000, B0000,
B1100, B1100, B1111, B1111, B0011, B0011, B0000, B0000,
B1100, B1100, B1111, B1111, B0011, B0011, B0000, B0000,
B1100, B1100, B1111, B1111, B0011, B0011, B0000, B0000,
 
B1100, B1100, B1111, B1111, B0011, B0011, B0000, B0000,
B1100, B1100, B1111, B1111, B0011, B0011, B0000, B0000,
B1100, B1100, B1111, B1111, B0011, B0011, B0000, B0000,
B1100, B1100, B1111, B1111, B0011, B0011, B0000, B0000,
 
// winky winky oney
B1111, B0111, B1111, B1011, B1111, B1101, B1111, B1110,
B1111, B0111, B1111, B1011, B1111, B1101, B1111, B1110,
B1111, B0111, B1111, B1011, B1111, B1101, B1111, B1110,
B1111, B0111, B1111, B1011, B1111, B1101, B1111, B1110,
 
B1111, B0111, B1111, B1011, B1111, B1101, B1111, B1110,
B1111, B0111, B1111, B1011, B1111, B1101, B1111, B1110,
B1111, B0111, B1111, B1011, B1111, B1101, B1111, B1110,
B1111, B0111, B1111, B1011, B1111, B1101, B1111, B1110,
//512
 
// flash 2
B1111, B1111, B0000, B0000, B1111, B1111, B0000, B0000,
B1111, B1111, B0000, B0000, B1111, B1111, B0000, B0000,
B1111, B1111, B0000, B0000, B1111, B1111, B0000, B0000,
B1111, B1111, B0000, B0000, B1111, B1111, B0000, B0000,
 
B1111, B1111, B0000, B0000, B1111, B1111, B0000, B0000,
B1111, B1111, B0000, B0000, B1111, B1111, B0000, B0000,
B1111, B1111, B0000, B0000, B1111, B1111, B0000, B0000,
B1111, B1111, B0000, B0000, B1111, B1111, B0000, B0000,
 
// bongos
B0100, B0010, B1000, B0001, B1000, B0010, B0100, B0001,
B0100, B0010, B1000, B0001, B1000, B0010, B0100, B0001,
B0100, B0010, B1000, B0001, B1000, B0010, B0100, B0001,
B0100, B0010, B1000, B0001, B1000, B0010, B0100, B0001,
 
B0100, B0010, B1000, B0001, B1000, B0010, B0100, B0001,
B0100, B0010, B1000, B0001, B1000, B0010, B0100, B0001,
B0100, B0010, B1000, B0001, B1000, B0010, B0100, B0001,
B0100, B0010, B1000, B0001, B1000, B0010, B0100, B0001,
 
//boom boom ta-ka ta-ka
B1111, B0000, B1111, B0000, B0111, B1110, B0111, B1110,
B1111, B0000, B1111, B0000, B1011, B1101, B1011, B1101,
B1111, B0000, B1111, B0000, B0111, B1110, B0111, B1110,
B1111, B0000, B1111, B0000, B1011, B1101, B1011, B1101,
 
B1111, B0000, B1111, B0000, B0111, B1110, B0111, B1110,
B1111, B0000, B1111, B0000, B1011, B1101, B1011, B1101,
B1111, B0000, B1111, B0000, B0111, B1110, B0111, B1110,
B1111, B0000, B1111, B0000, B1011, B1101, B1011, B1101,
 
//total random
B0100, B0010, B0001, B1000, B0010, B0100, B0001, B1000,
B0010, B0100, B1000, B0001, B0001, B1000, B0100, B0010,
B0100, B1000, B0010, B0001, B0001, B0010, B0100, B1000,
B0001, B1000, B0010, B0100, B0100, B0010, B1000, B0001,
 
B0100, B0010, B0001, B1000, B0010, B0100, B0001, B1000,
B0010, B0100, B1000, B0001, B0001, B1000, B0100, B0010,
B0100, B1000, B0010, B0001, B0001, B0010, B0100, B1000,
B0001, B1000, B0010, B0100, B0100, B0010, B1000, B0001,
//768
 
//pyramid med
B1000, B1100, B1110, B1111, B1110, B1100, B1000, B0000,
B1000, B1100, B1110, B1111, B1110, B1100, B1000, B0000,
B1000, B1100, B1110, B1111, B1110, B1100, B1000, B0000,
B1000, B1100, B1110, B1111, B1110, B1100, B1000, B0000,
 
B1000, B1100, B1110, B1111, B1110, B1100, B1000, B0000,
B1000, B1100, B1110, B1111, B1110, B1100, B1000, B0000,
B1000, B1100, B1110, B1111, B1110, B1100, B1000, B0000,
B1000, B1100, B1110, B1111, B1110, B1100, B1000, B0000,
 
//reverse pyramid
B0001, B0011, B0111, B1111, B0111, B0011, B0001, B0000,
B0001, B0011, B0111, B1111, B0111, B0011, B0001, B0000,
B0001, B0011, B0111, B1111, B0111, B0011, B0001, B0000,
B0001, B0011, B0111, B1111, B0111, B0011, B0001, B0000,
 
B0001, B0011, B0111, B1111, B0111, B0011, B0001, B0000,
B0001, B0011, B0111, B1111, B0111, B0011, B0001, B0000,
B0001, B0011, B0111, B1111, B0111, B0011, B0001, B0000,
B0001, B0011, B0111, B1111, B0111, B0011, B0001, B0000,
 
//creepy crawly
B1100, B1010, B0110, B0101, B0011, B1010, B1001, B0101,
B1100, B1010, B0110, B0101, B0011, B1010, B1001, B0101,
B1100, B1010, B0110, B0101, B0011, B1010, B1001, B0101,
B1100, B1010, B0110, B0101, B0011, B1010, B1001, B0101,
 
B1100, B1010, B0110, B0101, B0011, B1010, B1001, B0101,
B1100, B1010, B0110, B0101, B0011, B1010, B1001, B0101,
B1100, B1010, B0110, B0101, B0011, B1010, B1001, B0101,
B1100, B1010, B0110, B0101, B0011, B1010, B1001, B0101,
 
//triangle staircase
B1000, B1100, B1110, B1111, B0001, B0010, B0100, B1000,
B1000, B0100, B0010, B0001, B1111, B1110, B1100, B1000,
B1000, B1100, B1110, B1111, B0001, B0010, B0100, B1000,
B1000, B0100, B0010, B0001, B1111, B1110, B1100, B1000,
 
B1000, B1100, B1110, B1111, B0001, B0010, B0100, B1000,
B1000, B0100, B0010, B0001, B1111, B1110, B1100, B1000,
B1000, B1100, B1110, B1111, B0001, B0010, B0100, B1000,
B1000, B0100, B0010, B0001, B1111, B1110, B1100, B1000,
//1024
 
//flash up and down
B1000, B0000, B1100, B0000, B1110, B0000, B1111, B0000,
B1111, B0000, B0111, B0000, B0011, B0000, B1000, B0000,
B1000, B0000, B1100, B0000, B1110, B0000, B1111, B0000,
B1111, B0000, B0111, B0000, B0011, B0000, B1000, B0000,
 
B1000, B0000, B1100, B0000, B1110, B0000, B1111, B0000,
B1111, B0000, B0111, B0000, B0011, B0000, B1000, B0000,
B1000, B0000, B1100, B0000, B1110, B0000, B1111, B0000,
B1111, B0000, B0111, B0000, B0011, B0000, B1000, B0000,
 
//boom boom 1234
B1111, B0000, B1111, B0000, B0111, B1011, B1101, B1110,
B1111, B0000, B1111, B0000, B1110, B1101, B1011, B0111,
B1111, B0000, B1111, B0000, B0111, B1011, B1101, B1110,
B1111, B0000, B1111, B0000, B1110, B1101, B1011, B0111,
 
B1111, B0000, B1111, B0000, B0111, B1011, B1101, B1110,
B1111, B0000, B1111, B0000, B1110, B1101, B1011, B0111,
B1111, B0000, B1111, B0000, B0111, B1011, B1101, B1110,
B1111, B0000, B1111, B0000, B1110, B1101, B1011, B0111,
 
//flash up
B1000, B0000, B1100, B0000, B1110, B0000, B1111, B0000,
B1111, B0000, B0111, B0000, B0011, B0000, B0001, B0000,
B1000, B0000, B1100, B0000, B1110, B0000, B1111, B0000,
B1111, B0000, B0111, B0000, B0011, B0000, B0001, B0000,
 
B1000, B0000, B1100, B0000, B1110, B0000, B1111, B0000,
B1111, B0000, B0111, B0000, B0011, B0000, B0001, B0000,
B1000, B0000, B1100, B0000, B1110, B0000, B1111, B0000,
B1111, B0000, B0111, B0000, B0011, B0000, B0001, B0000,
 
//flash up and flash
B1000, B0000, B1100, B0000, B1110, B0000, B1111, B0000,
B1111, B1111, B0000, B0000, B1111, B1111, B0000, B0000,
B1111, B0000, B0111, B0000, B0011, B0000, B0001, B0000,
B1111, B1111, B0000, B0000, B1111, B1111, B0000, B0000,
 
B1000, B0000, B1100, B0000, B1110, B0000, B1111, B0000,
B1111, B1111, B0000, B0000, B1111, B1111, B0000, B0000,
B1111, B0000, B0111, B0000, B0011, B0000, B0001, B0000,
B1111, B1111, B0000, B0000, B1111, B1111, B0000, B0000
//1280
 
 
// <-leave comma off the last value
 
};
 
void setup() {
 
Serial.begin(9600);
 
pinMode(relayAPin, OUTPUT);
pinMode(relayBPin, OUTPUT);
pinMode(relayCPin, OUTPUT);
pinMode(relayDPin, OUTPUT);
pinMode(relayEPin, OUTPUT);
pinMode(relayFPin, OUTPUT);
pinMode(relayGPin, OUTPUT);
pinMode(relayHPin, OUTPUT);
 
Serial.println("Flash program, by Alexander Reben ArEbEn alex@areben.com");
 
}
 
void loop(){
currentMillis = millis();
int potValue = analogRead(potPin);
int delayPot = map(potValue, 0, 1024, lowRate, highRate);
updateLightBlink(pattern, patternLength, delayPot);
 
}
 
void updateLightBlink (byte input[], int length, int interval){
if(currentMillis - previousMillis > interval) {
digitalWrite(relayAPin, (input[currentPattern] & B00000001));
digitalWrite(relayBPin, (input[currentPattern] & B00000010));
digitalWrite(relayCPin, (input[currentPattern] & B00000100));
digitalWrite(relayDPin, (input[currentPattern] & B00001000));
digitalWrite(relayEPin, (input[currentPattern] & B00010000));
digitalWrite(relayFPin, (input[currentPattern] & B00100000));
digitalWrite(relayGPin, (input[currentPattern] & B01000000));
digitalWrite(relayHPin, (input[currentPattern] & B10000000));
 
if(currentPattern < length - 1)
{
currentPattern++;
}
else
{
currentPattern = 0;
}
 
previousMillis = currentMillis;
}
 
return;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.