From 1af698cde1d019951fc90edb63282d0467c6b6a9 Mon Sep 17 00:00:00 2001 From: Stefan Rupp Date: Mon, 14 Apr 2014 16:36:36 +0200 Subject: [PATCH] add fancy new pattern --- rgbyteclock.c | 2 +- rgbyteclock_patterns.c | 76 ++++++++++++++++++++++++++++++++++++++++++ rgbyteclock_patterns.h | 1 + 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/rgbyteclock.c b/rgbyteclock.c index 6a14eab..0753a52 100644 --- a/rgbyteclock.c +++ b/rgbyteclock.c @@ -5,7 +5,7 @@ void rgbyteclock(void) { - rgbyteclock_rounds(); + rgbyteclock_rounds_colored(); while (1) { diff --git a/rgbyteclock_patterns.c b/rgbyteclock_patterns.c index 7e8aacd..11a133a 100644 --- a/rgbyteclock_patterns.c +++ b/rgbyteclock_patterns.c @@ -52,6 +52,82 @@ void rgbyteclock_rounds(void) } +void rgbyteclock_rounds_white(void) +{ + uint16_t brightness = 0x1fff; + uint16_t brightness_last = 0x1fff; + uint8_t direction_b = 1, direction_d = 1; + uint8_t dir_count=0, dir_steps=0; + uint8_t color_start = 0; + uint8_t color; + uint8_t delay = 200, delay_last = 200; + led_turn_all_on(); + + while (1) { + color_start++; + if (color_start > 2) { color_start = 0; } + color = color_start; + for (int led=0; led<12; led++) { + color++; + switch (color) { + case 1: + led_set(led, 0x00, brightness, 0x00); + break; + case 2: + led_set(led, 0x00, 0x00, brightness); + break; + default: + color = 0; + led_set(led, brightness, 0x00, 0x00); + break; + } + } + led_flush(); + timer_wait(delay); + + #if 0 + if (direction_b) { + brightness = brightness + brightness/16; + if (brightness_last > brightness) { + brightness = 0xffff; + direction_b = 0; + } + brightness_last = brightness; + } + else { + brightness = brightness - brightness/8; + if (brightness < 0x00ff) { + brightness = 0x00ff; + direction_b = 1; + } + brightness_last = brightness; + } + #endif + + if (dir_count++ > dir_steps) { + if (direction_d) { + delay *= 0.90; + if (delay == delay_last) { delay--; } + if (delay < 5) { + direction_d = 0; + } + } + else { + delay *= 1.10; + if (delay == delay_last) { delay++; } + if (delay >= 200) { + direction_d = 1; + } + } + delay_last = delay; + dir_count = 0; + dir_steps = (200/delay)+1; + } + } +} + + + void rgbyteclock_rounds_colored(void) { uint16_t brightness = 0x00ff; diff --git a/rgbyteclock_patterns.h b/rgbyteclock_patterns.h index e550db8..d81c442 100644 --- a/rgbyteclock_patterns.h +++ b/rgbyteclock_patterns.h @@ -21,6 +21,7 @@ void rgbyteclock_rounds(void); void rgbyteclock_rounds_colored(void); +void rgbyteclock_rounds_white(void); void rgbyteclock_secwatch(void); void rgbyteclock_secwatch_glide(void);