RGB Lights

Dependencies:   mbed PinDetect

Files at this revision

API Documentation at this revision

Comitter:
10724928
Date:
Wed Nov 10 13:07:28 2021 +0000
Parent:
7:bd8ad736bd09
Commit message:
RGB Lights at different light levels

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r bd8ad736bd09 -r 3949ee5c0083 main.cpp
--- a/main.cpp	Wed Nov 10 12:25:49 2021 +0000
+++ b/main.cpp	Wed Nov 10 13:07:28 2021 +0000
@@ -15,6 +15,11 @@
 #define TITLE_OFFSET    (16+LED_RADIUS)      
 
 AnalogIn lightLevel(P10_0);
+DigitalOut lights(LED4);
+DigitalOut lightsR(LED1);
+DigitalOut lightsG(LED2);
+DigitalOut lightsB(LED3);
+bool lightStatus;
 
 void Display_Init(void)
 {
@@ -34,11 +39,15 @@
 
 int main()
 {
+    int lowThresh, highThresh;
+    lowThresh = 40;
+    highThresh = 70;
+    lights = 0;  
     /* Initialise display */
     Display_Init();
 
-    printf("light level\r\n");
-
+    printf("Light Level Control\r\n");
+    lightStatus = false;
     GUI_SetFont(GUI_FONT_D60X80);
     GUI_SetColor(GUI_WHITE);
     while(true) {
@@ -46,6 +55,25 @@
         int lightPercent;
         lightPercent = (lightLevel.read_u16()*100)/65535;
         printf("light level is %d\r\n",lightPercent);
+        if(lightPercent > highThresh) lightStatus = 1;
+        else if (lightPercent < lowThresh) lightStatus = 0;
+        lights = lightStatus;
+        if(lightPercent > highThresh) {
+            lightsB = 0;
+            lightsR = 1;
+            lightsG = 1;
+            }
+        if(lightPercent < highThresh && lightPercent > lowThresh) {
+            lightsB = 1;
+            lightsR = 1;
+            lightsG = 0;
+            } 
+        if(lightPercent < lowThresh) {
+            lightsB = 1;
+            lightsR = 0;
+            lightsG = 1;
+            }
+            
         ThisThread::sleep_for(1000);
         char buffer[16];
         sprintf(buffer,"%d",lightPercent);