On board LED blinky example for Wio cellular targets - Seeed Wio 3G and Wio LTE-M1/NB1(BG96)

Dependencies:   WS2812 PixelArray

Files at this revision

API Documentation at this revision

Comitter:
MACRUM
Date:
Sat Aug 25 09:08:54 2018 +0000
Parent:
0:1f050f0c9bec
Child:
2:a7b22ec9b6f8
Commit message:
Add setcolor function

Changed in this revision

Wio_3G_LED.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Wio_3G_LED.h	Sat Aug 25 09:08:54 2018 +0000
@@ -0,0 +1,35 @@
+#include "WS2812.h"
+#include "PixelArray.h"
+
+#define WS2812_BUF 8
+#define NUM_COLORS 8
+#define NUM_LEDS_PER_COLOR 8
+#define H0 8
+#define L0 32
+#define H1 17
+#define L1 32
+
+DigitalOut LEDPower(PE_8, 1);
+PixelArray px(WS2812_BUF);
+WS2812 ws(PB_1, WS2812_BUF, H0, L0, H1, L1);
+
+const int colorbuf[NUM_COLORS] = {0x000000, 0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f, 0x2f2f2f};
+
+enum ws2812_color {
+    WS2812_BLACK = 0,
+    WS2812_RED,
+    WS2812_YELLOW,
+    WS2812_GREEN,
+    WS2812_CYAN,
+    WS2812_BLUE,
+    WS2812_PURPLE,
+    WS2812_WHITE
+};
+
+void setcolor(int color)
+{
+    px.Set(0, colorbuf[color]);
+    px.SetI(0, 0x80);
+    ws.write_offsets(px.getBuf(), 0, 0, 0);
+
+}
--- a/main.cpp	Thu Aug 09 06:44:01 2018 +0000
+++ b/main.cpp	Sat Aug 25 09:08:54 2018 +0000
@@ -1,42 +1,14 @@
 #include "mbed.h"
-#include "WS2812.h"
-#include "PixelArray.h"
-
-#define WS2812_BUF 8
-#define NUM_COLORS 8
-#define NUM_LEDS_PER_COLOR 8
-#define H0 8
-#define L0 32
-#define H1 17
-#define L1 32
-
-DigitalOut LEDPower(PE_8, 1);
-PixelArray px(WS2812_BUF);
-WS2812 ws(PB_1, WS2812_BUF, H0, L0, H1, L1);
-
-const int colorbuf[NUM_COLORS] = {0x000000, 0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f, 0x2f2f2f};
+#include "Wio_3G_LED.h"
 
 // main() runs in its own thread in the OS
 int main()
 {
-    ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling
-
-    // for each of the colours (j) write out 10 of them
-    // the pixels are written at the colour*10, plus the colour position
-    // all modulus 60 so it wraps around
-    for (int i = 0; i < WS2812_BUF; i++) {
-        px.Set(i, colorbuf[i]);
-        px.SetI(i, 0x80);
+    while (1) {
+        setcolor(WS2812_RED);
+        wait(0.5);
+        setcolor(WS2812_BLACK);
+        wait(0.5);
     }
 
-    int col = 0;
-
-    while (true) {
-        ws.write_offsets(px.getBuf(), col, col, col);
-        col++;
-        if (col >= WS2812_BUF) {
-            col = 0;
-        }
-        wait(0.5);
-    }
 }