From 81442c7a6c37e695ae7f54436927421dd2c25cf0 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 30 Jun 2012 19:18:53 +0200 Subject: [PATCH] autonomous: Support multiple TLCs --- arduino/autonomous/autonomous.ino | 49 ++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/arduino/autonomous/autonomous.ino b/arduino/autonomous/autonomous.ino index 415b3ff..b625576 100644 --- a/arduino/autonomous/autonomous.ino +++ b/arduino/autonomous/autonomous.ino @@ -1,25 +1,33 @@ #include "../ledbar.h" +#define NUM_TLCS 3 + +#define TLCCH(tlc_num, ch_num) ((tlc_num) << 4 | (ch_num)) + #define CH 3 -#define TLCCH(tlc_num, ch_num) (ch_num) /* FIXME */ - unsigned int xr1 = 19543; -int cpin[][CH] = { +class Ledbar lb[NUM_TLCS]; + +int cpin[5 * NUM_TLCS][CH] = { {TLCCH(0, 2), TLCCH(0, 1), TLCCH(0, 0)}, {TLCCH(0, 5), TLCCH(0, 4), TLCCH(0, 3)}, {TLCCH(0, 8), TLCCH(0, 7), TLCCH(0, 6)}, - {TLCCH(0, 12), TLCCH(0, 11),TLCCH(0, 10)}, - {TLCCH(0, 15),TLCCH(0, 14),TLCCH(0, 13)}, + {TLCCH(0, 11), TLCCH(0, 10),TLCCH(0, 9)}, + {TLCCH(0, 14),TLCCH(0, 13),TLCCH(0, 12)}, -#if 0 {TLCCH(1, 2), TLCCH(1, 1), TLCCH(1, 0)}, {TLCCH(1, 5), TLCCH(1, 4), TLCCH(1, 3)}, {TLCCH(1, 8), TLCCH(1, 7), TLCCH(1, 6)}, - {TLCCH(1, 12), TLCCH(1, 11), TLCCH(1, 10)}, - {TLCCH(1, 15), TLCCH(1, 14), TLCCH(1, 13)}, -#endif + {TLCCH(1, 11), TLCCH(1, 10),TLCCH(1, 9)}, + {TLCCH(1, 14),TLCCH(1, 13),TLCCH(1, 12)}, + + {TLCCH(2, 2), TLCCH(2, 1), TLCCH(2, 0)}, + {TLCCH(2, 5), TLCCH(2, 4), TLCCH(2, 3)}, + {TLCCH(2, 8), TLCCH(2, 7), TLCCH(2, 6)}, + {TLCCH(2, 11), TLCCH(2, 10),TLCCH(2, 9)}, + {TLCCH(2, 14),TLCCH(2, 13),TLCCH(2, 12)}, }; #define cpinsets (sizeof(cpin)/sizeof(cpin[0])) @@ -30,6 +38,18 @@ int cmax[cpinsets][CH] = { { 100, 250, 138 }, { 100, 240, 230 }, { 100, 230, 188 }, + + { 100, 250, 138 }, + { 100, 250, 138 }, + { 100, 250, 138 }, + { 100, 240, 230 }, + { 100, 230, 188 }, + + { 100, 250, 138 }, + { 100, 250, 138 }, + { 100, 250, 138 }, + { 100, 240, 230 }, + { 100, 230, 188 }, }; int c[cpinsets][CH]; @@ -38,12 +58,13 @@ int wait = 10; void setup() { Serial.begin(9600); - Ledbar.begin(B1100000); int i = 0, led = 0; + for (i = 0; i < NUM_TLCS; i++) + lb[i].begin(B1100000 | i); for (led = 0; led < cpinsets; led++) { for (i = 0; i < CH; i++) { c[led][i] = cmax[led][i] / 2; - Ledbar.setPinMode(cpin[led][i], LPM_PWM); + lb[cpin[led][i] >> 4].setPinMode(cpin[led][i] & 0xf, LPM_PWM); } } xr1 += analogRead(0); @@ -171,10 +192,10 @@ void loop() } int i; - for (i = 0; i < CH; i++) { - for (led = 0; led < cpinsets; led++) { + for (led = 0; led < cpinsets; led++) { + for (i = 0; i < CH; i++) { //Serial.print(cpin[led][i], DEC); Serial.print("="); Serial.print(c[led][i], DEC); Serial.print("/"); Serial.print(cmax[led][i], DEC); Serial.print(" "); - Ledbar.setPinPWM(cpin[led][i], c[led][i]); + lb[cpin[led][i] >> 4].setPinPWM(cpin[led][i] & 0xf, c[led][i]); } } //Serial.print(NUM_TLCS, DEC);