summaryrefslogtreecommitdiff
path: root/pwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'pwm.c')
-rw-r--r--pwm.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/pwm.c b/pwm.c
index 3436e9f..0641a80 100644
--- a/pwm.c
+++ b/pwm.c
@@ -28,15 +28,15 @@ volatile uint16_t value_blue = 1024;
void pwm_set_rgb(uint8_t r, uint8_t g, uint8_t b)
{
- value_red = r << 4;
- value_green = g << 4;
- value_blue = b << 4;
+ value_red = (uint16_t)r * r >> 4;
+ value_green = (uint16_t)g * g >> 4;
+ value_blue = (uint16_t)b * b >> 4;
}
void pwm_tick(void)
{
for (uint16_t i = 0; i < 4096; i++) {
- // this should take about the same time for each iteration, regardless of pulse width
+ /* 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) |