summaryrefslogtreecommitdiffstats
path: root/blinky.c
diff options
context:
space:
mode:
authorroot <root@no.no.james.local>2014-12-08 18:39:07 +0000
committerroot <root@no.no.james.local>2014-12-08 18:39:07 +0000
commit804820fe687affa38a52e302179e4a2293cb1ffb (patch)
treeacb784fd60af24d8c389e366d74409c75802dfa0 /blinky.c
downloadrgb_ring-804820fe687affa38a52e302179e4a2293cb1ffb.tar.gz
rgb_ring-804820fe687affa38a52e302179e4a2293cb1ffb.tar.bz2
rgb_ring-804820fe687affa38a52e302179e4a2293cb1ffb.zip
fish
Diffstat (limited to 'blinky.c')
-rw-r--r--blinky.c99
1 files changed, 99 insertions, 0 deletions
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;
+ }
+}