diff options
-rw-r--r-- | pwm.c | 22 |
1 files changed, 7 insertions, 15 deletions
@@ -35,21 +35,13 @@ void pwm_set_rgb(uint8_t r, uint8_t g, uint8_t b) void pwm_worker_loop(void) { for (;;) { - if (value_red) - PORTA |= (1 << PA0); - if (value_green) - PORTA |= (1 << PA1); - if (value_blue) - PORTA |= (1 << PA2); - - for (uint16_t i = 0; i < 4096; i++) { - if (value_red < i) - PORTA &= ~(1 << PA0); - if (value_green < i) - PORTA &= ~(1 << PA1); - if (value_blue < i) - PORTA &= ~(1 << PA2); - } + for (uint16_t i = 0; i < 4096; i++) { + // this should take about the same time for each iteration, regardless of pulse width + PORTA= (PORTA & ~((1<<PA0)|(1<<PA1)|(1<<PA2))) | + (value_red > i? (1<<PA0): 0) | + (value_green > i? (1<<PA1): 0) | + (value_blue > i? (1<<PA2): 0); + } } } |