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:
sepp_nepp
Date:
Fri Jun 21 15:25:05 2019 +0000
Parent:
7:92f47cf3a6fd
Commit message:
Add New Module LEDs_Car to the Library: directly handles all four LED lamps of a Car/Robot.

Changed in this revision

LEDs_Car.cpp Show annotated file Show diff for this revision Revisions of this file
LEDs_Car.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LEDs_Car.cpp	Fri Jun 21 15:25:05 2019 +0000
@@ -0,0 +1,85 @@
+// *****************************************************************
+// Handle all the LEDs with some general function wrappers functions
+// *****************************************************************
+#include "LEDs_Car.h"
+
+// Added a lookup function from a color number to a color, used by Creabot
+int LEDs_Car::ColNr2Color( char ColNr)
+{  switch (ColNr) {
+    case 0: return BLACK;
+    case 1: return WHITE;
+    case 2: return RED;
+    case 3: return GREEN;
+    case 4: return BLUE;
+    case 5: return PURPLE;
+    default: return BLACK;
+    }
+}
+
+void LEDs_Car::LEDsOff( void ) {
+    StopRotation();
+    StopBlink() ;
+    for (int lNr=0; lNr<NumLEDs; lNr++) 
+        { SetColor(BLACK,lNr); } 
+}
+
+void LEDs_Car::LEDsRainbow( void )
+{ for (int Nr=0; Nr<NumLEDs; Nr++) 
+    { SetColor(ColNr2Color(Nr + 1),Nr); }   
+}
+
+void LEDs_Car::LEDNrCol(LED_Nr aNr, int parameter) 
+{   
+  SetColor( ColNr2Color( aNr ), aNr);
+}
+
+void LEDs_Car::LEDsRainbowMove( double speed )
+{   LEDsRainbow( );
+    StartRotation(0.3);
+}
+
+void LEDs_Car::LEDClignote(LED_Nr aNr, int OnOff) {
+    if (OnOff == 1) {
+        SetColor( ORANGE, aNr);
+        StartBlink(0.5) ;} 
+    else { LEDsOff(); }
+}
+
+// *****************************************************************
+// Handle all the LEDs specifically with the LED Position definitions
+// *****************************************************************
+
+void LEDs_Car::LEDFront(int ColNr) 
+{   
+  SetColor( ColNr2Color( ColNr ), ledAvD);
+  SetColor( ColNr2Color( ColNr ), ledAvG);
+}
+  
+void LEDs_Car::LEDRear(int ColNr) 
+{   
+  SetColor( ColNr2Color( ColNr ), ledArD);
+  SetColor( ColNr2Color( ColNr ), ledArG);
+}
+  
+void LEDs_Car::LEDCligR(int speed) {
+    if ( (speed>0) && (speed<4) ) {
+       SetColor(ORANGE, ledAvD) ;
+       SetColor(ORANGE, ledArD) ;
+       StartBlink(float(speed)/4) ;} 
+    else { LEDsOff(); }
+ }
+
+void LEDs_Car::LEDCligL(int speed) {
+    if ( (speed>0) && (speed<4) ) {
+       SetColor(ORANGE, ledAvG) ;
+       SetColor(ORANGE, ledArG) ;
+       StartBlink(float(speed)/4) ;} 
+    else { LEDsOff(); }
+}
+
+void LEDs_Car::LEDAnim(int speed) {
+    if ( (speed>0) && (speed<4) ) 
+        { LEDsRainbowMove(float(speed)/4); }
+      else {  LEDsOff();  }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LEDs_Car.h	Fri Jun 21 15:25:05 2019 +0000
@@ -0,0 +1,60 @@
+
+#ifndef BOT_AUXILIARIES_H
+#define BOT_AUXILIARIES_H
+
+#include "mbed.h"
+#include "LED_WS2812.h"
+#include <string> 
+
+// Put the LED names in the order they are chained up 
+enum LED_Nr{ ledAvG, ledAvD, ledArD, ledArG, NumLEDs };
+
+// *****************************************************************
+// Handle all the LEDs with some general function wrappers functions
+// *****************************************************************
+
+/** Control 4 LEDs around the Car: front / rear, left / right
+ *
+ * Example:
+ * @code
+ * // --- Define the PIN where the LED band is connected -----
+ * LEDs_Car ledBand(PB_5,4);
+ * Setup rainbow colors for the ledBand
+ * ledBand.LEDsRainbow();
+ * Rotate the colors for the ledBand
+ * ledBand.StartRotation(0.6) ;
+ * Turn off the LEDs:
+ * ledBand.LEDsOff();
+ * @endcode
+ */
+
+
+class LEDs_Car: public LED_WS2812
+{
+  public:
+   /** Create a Car-LED object to control the four LEDs around the car
+     *
+     *  @param PinName Pin Name through wich the LEDs are controlled
+     *  @param _nbLeds Number of LEDs actually implemented, defaults to 4
+     */
+    LEDs_Car(PinName _PinOut,  int _nbLeds):LED_WS2812(_PinOut, _nbLeds) {  };
+    
+    void LEDsOff( void );
+    void LEDsRainbow( void );
+    void LEDNrCol(LED_Nr aNr, int parameter) ;
+    void LEDsRainbowMove( double speed );
+    void LEDClignote(LED_Nr aNr, int OnOff);
+    int ColNr2Color( char ColNr);
+
+    // *****************************************************************
+    // Handle all the LEDs specifically with the LED Position definitions
+    // *****************************************************************
+    
+    void LEDFront(int ColNr) ;
+    void LEDRear(int ColNr) ;
+    void LEDCligR(int speed);
+    void LEDCligL(int speed);
+    void LEDAnim(int speed);
+}; // class LEDs_Car
+
+#endif
\ No newline at end of file