Source code for the Curilights Controller. See http://www.saccade.com/writing/projects/CuriController/ for details.

Dependencies:   FatFileSystem mbed

This is the source code for the Curilights controller. This lets you interactively control a string of Curilights. It provides a simple click-wheel user interface for changing colors, brightness and behavior. It responds to movement and lighting.

Finished Controller

/media/uploads/isonno/nxp3872_controllerclose.jpg

System Block Diagram

/media/uploads/isonno/blockdiagram.png

Revision:
3:0ac64c4ca40f
Parent:
1:d1da77023e6a
--- a/main.cpp	Sun Jan 15 09:07:04 2012 +0000
+++ b/main.cpp	Tue Jan 17 13:45:17 2012 +0000
@@ -18,25 +18,10 @@
 #include "SettingsMenu.h"
 
 #include "RGBLED.h"
+#include "DebugLED.h"
 
 #include <string>
 
-// Blinking LEDs on the mbed board are used
-// for light/motion sensor diagnostics
-
-const int NumLEDs = 4;
-DigitalOut leds[NumLEDs] = { DigitalOut(LED1),
-                             DigitalOut(LED2),
-                             DigitalOut(LED3),
-                             DigitalOut(LED4) };
-
-void cycleLEDs() {
-    static int curLED = 0;
-    leds[curLED] = 0;
-    curLED = (curLED + 1) % NumLEDs;
-    leds[curLED] = 1;
-}
-
 // Light sensor wrapper
 class LightSensor
 {
@@ -44,7 +29,7 @@
     LightSensor() : fLightPin( p19 ) {};
     
 //    int light() { return (int)(fLightPin.read() * 1000); }
-    int32_t light() {HoldInterrupts noirq; float a = fLightPin.read(); return (int)(a * 1000); }
+    int32_t light() {volatile float a = fLightPin.read(); return (int)(a * 1000); }
 
 private:
     AnalogIn fLightPin;
@@ -185,7 +170,6 @@
 
     LightString curiLights( p9, 58 );
     curiLights.InitLights();
-    curiLights.AttachUSBSerial();
     
     RotaryEncoder knob( p17, p18 );
     PushButton knobButton( p30, "Knob" );
@@ -202,7 +186,7 @@
     // the motion detector.  All other input is
     // handled via interrupts.
     
-    leds[0] = leds[1] = leds[2] = leds[3] = 0;
+    gLeds[0] = gLeds[1] = gLeds[2] = gLeds[3] = 0;
     gDebugLED.Set(0);
 
     while(1) {
@@ -211,14 +195,18 @@
 //        printf( "LightSensor: %d\r\n", lightSensor.light() );
         
 //        CheckDownloadedPattern( curiLights );
+        // If the lightSensor shows enough light, OR the light sensor is disabled.
+        bool lightSensorState = (lightSensor.light() < 800)  || (gSystemState.GetLightSensor() == 0);
         
-        homeMenu.SetLightsOn( (lightSensor.light() < 800) || motionDelay.IsWaiting() );
+        homeMenu.SetLightsOn( lightSensorState || motionDelay.IsWaiting() );
             
         if (mdetect.IsMotionDetected())
         {
             motionDelay.Start( 10 );
-            leds[0] = 1; leds[1] = 1; leds[2] = 1; leds[3] = 1;
+            gLeds[0] = 1; gLeds[1] = 1; gLeds[2] = 1; gLeds[3] = 1;
             wait(0.6);
         }
+        
+        curiLights.FlushOutput();
     }
 }