From 804820fe687affa38a52e302179e4a2293cb1ffb Mon Sep 17 00:00:00 2001 From: root Date: Mon, 8 Dec 2014 18:39:07 +0000 Subject: fish --- blinky.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 blinky.c (limited to 'blinky.c') diff --git a/blinky.c b/blinky.c new file mode 100644 index 0000000..4b92d4c --- /dev/null +++ b/blinky.c @@ -0,0 +1,99 @@ +/* +* Light_WS2812 library example - RGB_blinky +* +* cycles one LED through red, green, blue +* +* This example is configured for a ATtiny85 with PLL clock fuse set and +* the WS2812 string connected to PB4. +*/ + +#include "project.h" + + +#define N_COLORS 288 +#define N_LEDS 24 + + +struct RGB color[N_COLORS]; +struct RGB led[N_LEDS]; + + +static int +map (int j, int n) +{ + j = (255UL * j) / n; + if (j > 255) + j = 255; + + return j; +} + +int +ramp (int j, int n) +{ + + if ((j >= -n) && (j < 0)) + return map (j + n, n); + if ((j >= 0) && (j <= n)) + return map (n - j, n); + + return 0; +} + + +static void +setup_colors (struct RGB *colors, int n) +{ + int i; + + int n3 = n / 3; + + for (i = 0; i < n; ++i) + { + colors[i].r = ramp (((i) % n) - n3, n3); + colors[i].g = ramp (((i + n3) % n) - n3, n3); + colors[i].b = ramp (((i + n3 + n3) % n) - n3, n3); + + printf ("%3d: %3d %3d %3d\n", i, colors[i].r, colors[i].g, colors[i].b); + + } +} + + + + +int +main (void) +{ + int i, j, k; + + setup_clocks (); + stdio_init (); + + + setup_colors (color, N_COLORS); + + + i = 0; + + while (1) + { + + for (j = 0; j < N_LEDS; ++j) + { + k = (j * (N_COLORS - 1)) / (N_LEDS - 1); + k += i; + while (k >= N_COLORS) + k -= N_COLORS; + + led[j] = color[k]; + } + + ws2812_setleds (led, N_LEDS); + _delay_ms (5); // wait for 500ms. + + + i++; + i %= N_COLORS; + } +} -- cgit v1.2.3