WS2812 / Test Program

Dependencies:   mbed WS2812 PixelArray

Files at this revision

API Documentation at this revision

Comitter:
villemejane
Date:
Mon Dec 13 08:59:15 2021 +0000
Parent:
6:67eded37186e
Commit message:
WS2812-Test Program

Changed in this revision

NeoPixel.lib Show diff for this revision Revisions of this file
PixelArray.lib Show annotated file Show diff for this revision Revisions of this file
WS2812.lib 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 67eded37186e -r 63d9073a1467 NeoPixel.lib
--- a/NeoPixel.lib	Tue Dec 12 08:06:55 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/teams/FCLabOvGU/code/NeoPixel/#037882a8e193
diff -r 67eded37186e -r 63d9073a1467 PixelArray.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PixelArray.lib	Mon Dec 13 08:59:15 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/villemejane/code/PixelArray/#fe962821e6a4
diff -r 67eded37186e -r 63d9073a1467 WS2812.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WS2812.lib	Mon Dec 13 08:59:15 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/IOGS_France/code/WS2812/#adfd3b002caa
diff -r 67eded37186e -r 63d9073a1467 main.cpp
--- a/main.cpp	Tue Dec 12 08:06:55 2017 +0000
+++ b/main.cpp	Mon Dec 13 08:59:15 2021 +0000
@@ -1,18 +1,100 @@
 #include "mbed.h"
-#include "neopixel.h"
+#include "PixelArray.h"
+#include "WS2812.h"
+
+#define WS2812_BUF  64
 
-NeoPixel npx(D6,8);
+#define BLACK       0x00000000
+#define WHITE       0x00FFFFFF
+#define WHITEW      0xFFFFFFFF
+#define GRAY        0x00808080
+#define RED         0x00FF0000
+#define ORANGE      0x00FFA500
+#define BLUE        0x000000FF
+#define DARKGREEN   0x00006400
+#define DARKCYAN    0x00008B8B
+#define INDIGO      0x004B0082
+
+/* Variables globales */
+Serial my_pc(USBTX, USBRX);
+PixelArray px(WS2812_BUF);
+int i;
 
-void setByte(uint8_t bits, uint32_t color)
-{
-    for (int i=0; i<8; i++) 
-        if (bits & 1 << i)
-            npx.setColor(i,color);
-        else
-            npx.setColor(i,0);    
-    npx.show();
+// For Nucleo F476 : 3, 12, 9, 12
+WS2812 ws(D7, WS2812_BUF, 3, 12, 9, 12);
+
+void afficheArray(PixelArray pxi, int size){
+    int k;
+    int *pixels = px.getBuf();
+    for(k = 0; k < size; k++){
+        my_pc.printf("i %d / pix %d \r\n", k, *(pixels+k));
+    }
+}
+
+void blackGrille(void){
+    for (i = 0; i < WS2812_BUF; i++) {
+        px.Set(i, BLACK);
+    }     
+    ws.write(px.getBuf());
+}
+
+void whiteGrille(void){
+    for (i = 0; i < WS2812_BUF; i++) {
+        px.Set(i, WHITEW);
+    }     
+    ws.write(px.getBuf());
 }
 
 int main() {
-   //binärer Zähler ;)
+    ws.useII(WS2812::GLOBAL);
+    ws.setII(100); 
+    /*
+    while(1){
+        for (i = 0; i < WS2812_BUF; i++) {
+            px.Set(i, 255);
+        }     
+        ws.write(px.getBuf());
+        wait(0.2);
+    }
+    
+    */
+    
+    blackGrille();
+    wait(1);
+    /*
+    whiteGrille();
+    wait(0.5);
+    blackGrille();
+    wait(0.5);
+    */
+    while(1){
+        /* Reinitialisation ecran */
+        
+        for (i = 0; i < WS2812_BUF; i++) {
+            px.Set(i, BLACK);
+        }     
+        ws.write(px.getBuf());
+        wait(0.2);
+        for (i = 0; i < WS2812_BUF; i++) {
+            px.Set(i, BLUE);
+        }     
+        ws.write(px.getBuf());
+        wait(0.2);
+        for (i = 0; i < WS2812_BUF; i++) {
+            px.Set(i, WHITE);
+        }     
+        ws.write(px.getBuf());
+        wait(0.2);
+        for (i = 0; i < WS2812_BUF; i++) {
+            px.Set(i, RED);
+        }     
+        ws.write(px.getBuf());
+        wait(0.2);
+        for (i = 0; i < WS2812_BUF; i++) {
+            px.Set(i, BLACK);
+        }     
+        ws.write(px.getBuf());
+        wait(1);   
+        
+    }
 }
diff -r 67eded37186e -r 63d9073a1467 mbed.bld
--- a/mbed.bld	Tue Dec 12 08:06:55 2017 +0000
+++ b/mbed.bld	Mon Dec 13 08:59:15 2021 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/fb8e0ae1cceb
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file