My Version of The LED_WS2812 Library

Dependencies:   WS2812 PixelArray

Fork of LED_WS2812 by CreaLab

Files at this revision

API Documentation at this revision

Comitter:
garphil
Date:
Thu Nov 02 09:56:59 2017 +0000
Parent:
2:2ba0fcde765c
Child:
4:15b992a39c77
Commit message:
Added SetColor at position + timing to wait after write.

Changed in this revision

LED_WS2812.cpp Show annotated file Show diff for this revision Revisions of this file
LED_WS2812.h Show annotated file Show diff for this revision Revisions of this file
--- a/LED_WS2812.cpp	Mon Jul 17 11:30:12 2017 +0000
+++ b/LED_WS2812.cpp	Thu Nov 02 09:56:59 2017 +0000
@@ -44,6 +44,22 @@
 
 
 
+void LED_WS2812::SetColor(LED_COLORS _color, int position) {
+      SetColor((unsigned int) _color, position);
+};
+
+void LED_WS2812::SetColor(unsigned int _color, int position) {
+      if(position < nbLeds && position >=0 ) {
+          pxArray->Set(position, _color);
+          pxArray->SetI(position,intensity);
+      
+      }
+      __writeBuf(0);
+      nbInsert = 0;
+      if(rotationState) StopRotation();
+       rotationPosition = nbLeds;
+};
+
 void LED_WS2812::SetColor(LED_COLORS _color) {
       SetColor((unsigned int) _color);
 };
@@ -67,6 +83,7 @@
 
 void LED_WS2812::__writeBuf(int z) {
      ws->write_offsets(pxArray->getBuf(),z,z,z);
+     wait(0.01);
  }
  
 void LED_WS2812::__insert2buf() {
--- a/LED_WS2812.h	Mon Jul 17 11:30:12 2017 +0000
+++ b/LED_WS2812.h	Thu Nov 02 09:56:59 2017 +0000
@@ -21,6 +21,7 @@
         BLUE        = 0x0000FF,
         LIGHTBLUE   = 0x00FFF6,
         RED         = 0xFF0000,
+        ORANGE      = 0xFFA500,
         GREEN       = 0X00FF00,
         BLACK       = 0X000000,
         WHITE       = 0XFFFFFF,
@@ -36,6 +37,8 @@
 public:
     LED_WS2812(PinName _PinOut,  int _nbLeds);
     ~LED_WS2812();
+    void SetColor(LED_COLORS _color, int position);
+    void SetColor(unsigned int _color, int position);
     void SetColor(unsigned int _color);
     void SetColor(LED_COLORS _color);
     void ResetColor();