dot star led strips

Dependents:   DotStarWall DotStarPoi

Files at this revision

API Documentation at this revision

Comitter:
Nathan Yonkee
Date:
Tue Aug 15 08:37:20 2017 -0600
Parent:
0:41708086172d
Commit message:
change initialization struct

Changed in this revision

DotStar.h Show annotated file Show diff for this revision Revisions of this file
--- a/DotStar.h	Fri Aug 11 18:34:49 2017 +0000
+++ b/DotStar.h	Tue Aug 15 08:37:20 2017 -0600
@@ -1,6 +1,12 @@
 #include "rtos.h"
 
+
+struct RedGreenBlue {
+    int red, green, blue;
+};
+
 class DotStar {
+    enum Init {brightness = 4, frequency = 500000, r = 35, g = 3, b = 0};
     SPI* const spi_;
     const int ledNum_;
     int brightness_;
@@ -13,18 +19,14 @@
     enum cmdType : char {
         setColor = '!',
         onOff = 'o',
-        switchStrip = 's'
     };
     void set_color(const int color, const int val);
+    void set_rgb(const RedGreenBlue& rgb);
     void set_leds();
     DotStar(SPI* const spi, const int nLeds);
     void set_brightness(const int brightness);
 };
 
-struct RedGreenBlue {
-    int red, green, blue;
-};
-
 class DotStarPair {
     DotStar* left;
     DotStar* right;
@@ -57,9 +59,9 @@
 DotStar::DotStar(SPI* const spi, const int nLeds) : spi_(spi), ledNum_(nLeds),
     brightness_(Init::brightness) {
     spi_->frequency(Init::frequency);
-    colors_[DotStar::red] = Init::red;
-    colors_[DotStar::blue] = Init::blue;
-    colors_[DotStar::green] = Init::green;
+    colors_[DotStar::red] = Init::r;
+    colors_[DotStar::blue] = Init::b;
+    colors_[DotStar::green] = Init::g;
     set_leds();
 }
 
@@ -82,8 +84,16 @@
 
 void DotStar::set_brightness(const int brightness) {
     brightness_ = brightness;
+    set_leds();
 }
 
+void DotStar::set_rgb(const RedGreenBlue& rgb) {
+    set_color(DotStar::blue, rgb.blue);
+    set_color(DotStar::red, rgb.red);
+    set_color(DotStar::green, rgb.green);
+    set_leds();
+};
+
 void DotStar::set_color(const int c, const int val) {
     colors_[c] = val;
 };