reordering LEDs: almost there

This commit is contained in:
Stefan Rupp 2014-03-13 03:03:08 +01:00
parent 3bf2dafcbf
commit fbdfb326e0
3 changed files with 109 additions and 39 deletions

View File

@ -29,29 +29,89 @@ static uint16_t ledbuffer[NUM_LED_CHANNELS];
static int8_t map_lednum_to_channels(uint8_t lednum, uint8_t *channel_r, uint8_t *channel_g, uint8_t *channel_b) static int8_t map_lednum_to_channels(uint8_t lednum, uint8_t *channel_r, uint8_t *channel_g, uint8_t *channel_b)
{ {
uint8_t ret; uint8_t ret=0;
if (lednum < 15) { if (lednum < 14) {
*channel_r = 3*lednum;
*channel_g = 3*lednum+1;
*channel_b = 3*lednum+2;
if ( lednum >= 10 ) {
*channel_r += 2;
*channel_g += 2;
*channel_b += 2;
}
else if ( lednum >= 5 ) {
*channel_r += 1;
*channel_g += 1;
*channel_b += 1;
}
ret = 1; ret = 1;
} switch (lednum) {
else { case 0:
ret = 0; *channel_r = 13;
*channel_g = 14;
*channel_b = 15;
break;
case 1:
*channel_r = 33;
*channel_g = 34;
*channel_b = 35;
break;
case 2:
*channel_r = 36;
*channel_g = 37;
*channel_b = 38;
break;
case 3:
*channel_r = 45;
*channel_g = 46;
*channel_b = 47;
break;
case 4:
*channel_r = 42;
*channel_g = 43;
*channel_b = 44;
break;
case 5:
*channel_r = 39;
*channel_g = 40;
*channel_b = 41;
break;
case 6:
*channel_r = 29;
*channel_g = 30;
*channel_b = 31;
break;
case 7:
*channel_r = 26;
*channel_g = 27;
*channel_b = 28;
break;
case 8:
*channel_r = 23;
*channel_g = 24;
*channel_b = 25;
break;
case 9:
*channel_r = 20;
*channel_g = 21;
*channel_b = 22;
break;
case 10:
*channel_r = 17;
*channel_g = 18;
*channel_b = 19;
break;
case 11:
*channel_r = 10;
*channel_g = 11;
*channel_b = 12;
break;
case 12:
*channel_r = 4;
*channel_g = 5;
*channel_b = 6;
break;
case 13:
*channel_r = 7;
*channel_g = 8;
*channel_b = 9;
break;
default:
ret = 0;
break;
}
} }
return ret; return ret;
} }
@ -157,9 +217,9 @@ void led_flush(void)
write_no_command(ledbuffer[channel+16]); write_no_command(ledbuffer[channel+16]);
write_data_latch(ledbuffer[channel+32]); write_data_latch(ledbuffer[channel+32]);
} }
write_no_command(ledbuffer[NUM_LED1642GW_CHANNELS-3]); write_no_command(ledbuffer[NUM_LED_CHANNELS-3]);
write_no_command(ledbuffer[NUM_LED1642GW_CHANNELS-2]); write_no_command(ledbuffer[NUM_LED_CHANNELS-2]);
write_global_latch(ledbuffer[NUM_LED1642GW_CHANNELS-1]); write_global_latch(ledbuffer[NUM_LED_CHANNELS-1]);
} }
@ -173,3 +233,8 @@ void ledcontroller_set_channel(uint8_t channel, uint16_t value)
} }
void ledcontroller_clear(void)
{
memset(ledbuffer, 0x00, sizeof(ledbuffer));
led_flush();
}

View File

@ -24,6 +24,8 @@ void led_flush(void);
void ledcontroller_turn_all_on(void); void ledcontroller_turn_all_on(void);
void ledcontroller_turn_all(void); void ledcontroller_turn_all(void);
void ledcontroller_set_channel(uint8_t channel, uint16_t value); void ledcontroller_set_channel(uint8_t channel, uint16_t value);
void ledcontroller_clear(void);
#endif // LEDCONTROLLER_H #endif // LEDCONTROLLER_H

View File

@ -24,37 +24,40 @@ void rgbyteclock(void)
while (1) { while (1) {
PORTC ^= (1<<PC5); PORTC ^= (1<<PC5);
for (int i=0; i<15; i++) { for (int i=0; i<14; i++) {
led_set(i, 0x7ff, 0x00, 0x00); led_set(i, 0x7ff, 0x00, 0x00);
led_flush(); led_flush();
timer_wait(500); timer_wait(1000);
} }
for (int i=0; i<15; i++) { /* for (int i=0; i<14; i++) { */
led_set(i, 0x00, 0x00, 0x00); /* led_set(i, 0x00, 0x00, 0x00); */
} /* } */
led_flush(); /* led_flush(); */
ledcontroller_clear();
timer_wait(100); timer_wait(100);
for (int i=0; i<15; i++) { for (int i=0; i<14; i++) {
led_set(i, 0x00, 0x7ff, 0x00); led_set(i, 0x00, 0x7ff, 0x00);
led_flush(); led_flush();
timer_wait(500); timer_wait(1000);
} }
for (int i=0; i<15; i++) { /* for (int i=0; i<14; i++) { */
led_set(i, 0x00, 0x00, 0x00); /* led_set(i, 0x00, 0x00, 0x00); */
} /* } */
led_flush(); /* led_flush(); */
ledcontroller_clear();
timer_wait(100); timer_wait(100);
for (int i=0; i<15; i++) { for (int i=0; i<14; i++) {
led_set(i, 0x00, 0x00, 0x7ff); led_set(i, 0x00, 0x00, 0x7ff);
led_flush(); led_flush();
timer_wait(500); timer_wait(1000);
} }
for (int i=0; i<15; i++) { /* for (int i=0; i<14; i++) { */
led_set(i, 0x00, 0x00, 0x00); /* led_set(i, 0x00, 0x00, 0x00); */
} /* } */
led_flush(); /* led_flush(); */
ledcontroller_clear();
timer_wait(100); timer_wait(100);
} }