mirror of
https://github.com/brmlab/ledbar.git
synced 2025-06-09 21:34:00 +02:00
autonomous: Use new Ledbar::setAllPinPWM() method, much faster LED control
This commit is contained in:
parent
db2cfc384b
commit
5a9884c360
2 changed files with 20 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue