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 12:01:51 2017 +0000
Parent:
3:ba8dc8811164
Child:
5:a5e2b86a7c32
Commit message:
Added Blink mode

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	Thu Nov 02 09:56:59 2017 +0000
+++ b/LED_WS2812.cpp	Thu Nov 02 12:01:51 2017 +0000
@@ -34,6 +34,8 @@
     ResetColor();
     rotationState = false;
     rotationPosition = nbLeds-1;
+    blinkState = false;
+    blinkONOFF = false;
     intensity = 0xff;
 };
   
@@ -162,6 +164,7 @@
 void LED_WS2812::StopRotation() {
     if(rotationState==true) {
         rotationState = false;
+        rotationPosition = 0;
         LEDSystemTick.detach();
     }
 }
@@ -170,5 +173,36 @@
     rotationPosition--;
     if (rotationPosition == -1)
         rotationPosition = nbLeds-1;
-     __writeBuf(rotationPosition);
+    if(!blinkState)  __writeBuf(rotationPosition);
+}
+
+
+void LED_WS2812::StartBlink(float interval) {
+    if(blinkState==false) {
+       blinkState = true;
+       LEDBlinkSystemTick.attach_us(this, &LED_WS2812::Blink, interval*1000000);
+    }
+}
+
+
+void LED_WS2812::StopBlink() {
+    if(blinkState==true) {
+        blinkState = false;
+        LEDBlinkSystemTick.detach();
+    }
+}
+
+void LED_WS2812::Blink() {
+    blinkONOFF = !blinkONOFF;
+    if (blinkONOFF)
+        __writeBuf(rotationPosition);
+    else {
+            ws->useII(WS2812::GLOBAL);
+            ws->setII(0);
+           __writeBuf(rotationPosition);
+            ws->useII(WS2812::PER_PIXEL);
+            ws->setII(intensity);
+            
+    }
+        
 }
\ No newline at end of file
--- a/LED_WS2812.h	Thu Nov 02 09:56:59 2017 +0000
+++ b/LED_WS2812.h	Thu Nov 02 12:01:51 2017 +0000
@@ -57,6 +57,10 @@
     void StartRotation(float interval); // itnerval in ms
     void StopRotation();  // interval in ms
     void Rotate(); // One Rotation
+    
+    void StartBlink(float interval); // itnerval in ms
+    void StopBlink();  // interval in ms
+    void Blink(); // One Rotation
       
 private:
     void __writeBuf(int z);
@@ -69,8 +73,11 @@
     int nbInsert;
     PixelArray *pxInsert;
     Ticker  LEDSystemTick;    // System Callback for Rotation
+    Ticker  LEDBlinkSystemTick;    // System Callback for Rotation
     bool rotationState;
+   bool blinkState;
     int rotationPosition;
+    bool blinkONOFF; // ON = true, OFF = false
     int intensity;
 };