Mark @RRVA / Mbed 2 deprecated rbChromaOffice

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_SimpleControls by RedBearLab

Files at this revision

API Documentation at this revision

Comitter:
MarkSPA
Date:
Fri Dec 09 15:50:13 2016 +0000
Parent:
5:1f6311e0fc14
Child:
7:0db51a3107fc
Commit message:
Fixed up most of the patterns

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
patterns.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Dec 02 14:33:16 2016 +0000
+++ b/main.cpp	Fri Dec 09 15:50:13 2016 +0000
@@ -54,6 +54,7 @@
 #define PATTERN_CANDY                    0x07
 #define PATTERN_SNOW                     0x08
 #define PATTERN_XMAS                     0x09
+#define PATTERN_ICE                      0x0A
 #define LEDS_ON                          0x01
 #define LEDS_OFF                         0x02
 
@@ -151,6 +152,14 @@
             blue = buf[3];
             pattern = buf[5];
         }
+        else
+        {
+            LEDS_ON_FLAG = 1;
+            red = buf[1];
+            green = buf[2];
+            blue = buf[3];
+            pattern = buf[5];
+        }
     }
 }
 
@@ -180,42 +189,39 @@
 {
     if ((radio_active == false) && (LEDS_ON_FLAG == 1)) {
         if (pattern == PATTERN_ON) {
-            for (uint8_t i = 0; i < NUM_LEDS; i++)
+            for (uint8_t i = 0; i <= NUM_LEDS; i++)
                 neopixel_set_color(&m_strip, i, red, green, blue);
             neopixel_show(&m_strip);
             
         } else if (pattern == PATTERN_FAST) {
-            neopixel_clear(&m_strip);
+            //neopixel_clear(&m_strip);
+            for (uint8_t i = 0; i <= NUM_LEDS; i++)
+                neopixel_set_color(&m_strip, i, 0, 0, 0);
             if (led_to_enable > NUM_LEDS)
                 led_to_enable = 0;
-
             neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
             neopixel_show(&m_strip);
             led_to_enable++;
         } else if (pattern == PATTERN_SLOW) {
-            if (slow_count > 20) {
-                slow_count = 0;
-                neopixel_clear(&m_strip);
-                if (led_to_enable > NUM_LEDS)
-                    led_to_enable = 0;
-
-                neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
-                neopixel_show(&m_strip);
-                led_to_enable++;
-            }
-            slow_count++;
+            for (uint8_t i = 0; i <= NUM_LEDS; i++)
+                neopixel_set_color(&m_strip, i, 0, 0, 0);
+            if (led_to_enable > NUM_LEDS)
+                led_to_enable = 0;
+            neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
+            neopixel_show(&m_strip);
+            led_to_enable++;
+            wait_ms(1000);
+            
         } else if (pattern == PATTERN_CHASE) {
             for (uint8_t i = 0; i < NUM_LEDS; i++)
                 neopixel_set_color(&m_strip, i, red, green, blue);
             neopixel_show(&m_strip);
+            
         } else if (pattern == PATTERN_MRB) {
             neopixel_clear(&m_strip);
             led_to_enable = rand()%NUM_LEDS;
-
             neopixel_set_color(&m_strip, led_to_enable, red, green, blue);
             neopixel_show(&m_strip);
-
-            led_to_enable++;
         }
 
         else if (pattern == PATTERN_RAINBOW)
@@ -225,10 +231,16 @@
             candyChase(100, NUM_LEDS, m_strip);
 
         else if (pattern == PATTERN_SNOW)
-            snowflakes(100, NUM_LEDS, m_strip);
+            snowflakes(250, NUM_LEDS, m_strip);
+            
+        else if (pattern == PATTERN_ICE)
+            iceflakes(250, NUM_LEDS, m_strip);
             
         else if (pattern == PATTERN_XMAS)
             xmas(200, NUM_LEDS, m_strip);
+            
+        else
+            neopixel_clear(&m_strip);
 
     }
 }
--- a/patterns.cpp	Fri Dec 02 14:33:16 2016 +0000
+++ b/patterns.cpp	Fri Dec 09 15:50:13 2016 +0000
@@ -38,78 +38,59 @@
 }
 
 void candyChase(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
-  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
-    for (int q=0; q < 3; q++) {
-      for (uint16_t i=0; i < numLEDs; i++) {
-        neopixel_set_color(&m_strip, i, 255,255,255);    //turn every pixel white
-      }
-      for (uint16_t i=0; i < numLEDs; i=i+3) {
-        neopixel_set_color(&m_strip, i, 255,0,0);    //turn every third pixel red
-      }
-      neopixel_show(&m_strip);
-
-      wait_ms(delay);
-
-      for (uint16_t i=0; i < numLEDs; i=i+3) {
-        neopixel_set_color(&m_strip, i, 0,0,0);        //turn every third pixel off
-      }
+    
+    for (int i=0; i < numLEDs; i++) 
+        neopixel_set_color(&m_strip, i, 255,255,255);  //turn every pixel white
+  
+    for (int i=0; i < numLEDs-1; i++) {
+        neopixel_set_color(&m_strip, i, 255,255,255);
+        neopixel_set_color(&m_strip, i+1, 255,0,0);    //turn on a red pixel and move it
+        neopixel_show(&m_strip);
+        wait_ms(delay); 
     }
-  }
+    wait_ms(delay);
+    
+    for (int i=0; i < numLEDs; i++) 
+        neopixel_set_color(&m_strip, i, 255,0,0);  //turn every pixel red
+  
+    for (int i=0; i < numLEDs-1; i++) {
+        neopixel_set_color(&m_strip, i, 255,0,0);
+        neopixel_set_color(&m_strip, i+1, 255,255,255);    //turn on a white pixel and move it
+        neopixel_show(&m_strip);
+        wait_ms(delay); 
+    }
 }
 
 void snowflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
 
-    // Setup the pixel array
-    int pixel[numLEDs];
-    for(int p=0; p<numLEDs; p++)
-      pixel[p] = rand()%255; 
-    
-
-    // Run some snowflake cycles
-    for (int j=0; j<20; j++) {
-        // Every five cycles, light a new pixel
-        if((j%5)==0)
-          neopixel_set_color(&m_strip, rand()%numLEDs, 255,255,255);
-        
-        // Dim all pixels by 10
-        for(int p=0; p<numLEDs; p++){
-          neopixel_set_color(&m_strip, p, pixel[p],pixel[p],pixel[p] );
-          pixel[p] =  pixel[p] - 10;
-        }
+    for (int i=0; i < numLEDs; i++) 
+        neopixel_set_color(&m_strip, i, 0,0,235);  //turn every pixel blue
+  
+    for (int i=0; i < numLEDs-1; i++) {
+        neopixel_set_color(&m_strip, i, 0,0,235);
+        neopixel_set_color(&m_strip, i+1, 255,255,255);    //turn on a white pixel and move it
         neopixel_show(&m_strip);
-        wait_ms(delay);
+        wait_ms(delay); 
     }
 }
 
 void iceflakes(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
-
-    // Setup the pixel array
-    int pixel[numLEDs];
-    for(int p=0; p<numLEDs; p++)
-      pixel[p] = rand()%255; 
     
-    // Run some snowflake cycles
-    for (int j=0; j<20; j++) {
-        // Every five cycles, light a new pixel
-        if((j%5)==0)
-          neopixel_set_color(&m_strip, rand()%numLEDs, 0,0,255);
-        
-        // Dim all pixels by 10
-        for(int p=0; p<numLEDs; p++){
-          neopixel_set_color(&m_strip, p, 0,0,pixel[p] );
-          pixel[p] =  pixel[p] - 10;
-        }
-       neopixel_show(&m_strip);
-       wait_ms(delay);
-    }
-}
+    for (int i=0; i < numLEDs; i++) 
+        neopixel_set_color(&m_strip, i, 235,235,235);  //turn every pixel white
+  
+    int led_to_enable = rand()%numLEDs;
+    neopixel_set_color(&m_strip, led_to_enable, 0, 0, 235); // set random blue
+    neopixel_show(&m_strip);
+    wait_ms(delay); 
+}  
 
 void xmas(int delay, uint8_t numLEDs, neopixel_strip_t m_strip) {
     //All green
     for (int j=0; j<numLEDs; j++) 
         neopixel_set_color(&m_strip, j, 0,255,0);
     neopixel_show(&m_strip);
-    wait_ms(delay);
+    wait_ms(500);
     //All red
     for (int j=0; j<numLEDs; j++) 
         neopixel_set_color(&m_strip, j, 255,0,0);
@@ -119,7 +100,7 @@
     for (int j=0; j<numLEDs; j++) 
         neopixel_set_color(&m_strip, j, 0,255,0);
     neopixel_show(&m_strip);
-    wait_ms(delay);
+    wait_ms(500);
     for (int j=0; j<numLEDs; j++) 
     {
         neopixel_set_color(&m_strip, j, 255,0,0);