diff --git a/arduino/autonomous/autonomous.ino b/arduino/autonomous/autonomous.ino index 0e9d6e1..3ae5e7a 100644 --- a/arduino/autonomous/autonomous.ino +++ b/arduino/autonomous/autonomous.ino @@ -143,15 +143,16 @@ void loop() //grey(led); } - int i; - 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(" "); - lb[cpin[led][i] >> 4].setPinPWM(cpin[led][i] & 0xf, c[led][i]); + for (int i = 0; i < NUM_TLCS; i++) { + // XXX: We assume static allocation of channels to pins 0..14 (in order) + // TODO: Just use unsigned char for c[] ? + unsigned char dutycycles[16]; + int *cblock = (int *) &c[i * LEDS_PER_TLC]; + for (int j = 0; j < 16; j++) { + dutycycles[j] = cblock[j]; } + lb[i].setAllPinPWM(dutycycles); } - //Serial.print(NUM_TLCS, DEC); - //Serial.println(); delay(wait); } diff --git a/arduino/ledbar.h b/arduino/ledbar.h index 7c4ffad..ba61d30 100644 --- a/arduino/ledbar.h +++ b/arduino/ledbar.h @@ -16,6 +16,7 @@ class Ledbar { /* pin is 0 .. 15 */ void setPinMode(int pin, enum LedbarPinMode pinMode); void setPinPWM(int pin, unsigned char dutyCycle); + void setAllPinPWM(unsigned char dutyCycles[16]); private: unsigned char address; unsigned char rawPinModes[4]; @@ -49,16 +50,26 @@ void Ledbar::setPinPWM(int pin, unsigned char dutyCycle) Wire.endTransmission(); } +void Ledbar::setAllPinPWM(unsigned char dutyCycles[16]) +{ + Wire.beginTransmission(address); + Wire.write(0b10100000 /* autoincrement */ | 0x2); + for (int i = 0; i < 16; i++) + Wire.write(dutyCycles[i]); + Wire.endTransmission(); +} + /** Current ledbar configuration: */ #define NUM_TLCS 2 +#define LEDS_PER_TLC 5 #define TLCCH(tlc_num, ch_num) ((tlc_num) << 4 | (ch_num)) #define CH 3 -const int cpin[5 * NUM_TLCS][CH] = { +const int cpin[LEDS_PER_TLC * NUM_TLCS][CH] = { {TLCCH(0, 0), TLCCH(0, 1), TLCCH(0, 2)}, {TLCCH(0, 3), TLCCH(0, 4), TLCCH(0, 5)}, {TLCCH(0, 6), TLCCH(0, 7), TLCCH(0, 8)},