Andy Jarvis
/
CITY3032-TEMPLATELIGHTsensor2
TEMPLATE light sensor 3 fork
Revision 8:ab7982d1ce50, committed 2021-11-10
- Comitter:
- 10740761
- Date:
- Wed Nov 10 13:06:53 2021 +0000
- Parent:
- 7:5e220d3e8a94
- Commit message:
- light sensor v3
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 5e220d3e8a94 -r ab7982d1ce50 main.cpp --- a/main.cpp Wed Nov 10 11:47:39 2021 +0000 +++ b/main.cpp Wed Nov 10 13:06:53 2021 +0000 @@ -15,6 +15,13 @@ #define TITLE_OFFSET (16+LED_RADIUS) AnalogIn lightlevel(P10_0); +DigitalOut lights(LED4); +DigitalOut lightsR(LED1); +DigitalOut lightsG(LED3); +DigitalOut lightsB(LED2); + + +bool lightStatus; void Display_Init(void) { @@ -34,10 +41,17 @@ int main() { + int lowThresh, highThresh; + lowThresh = 40; + highThresh = 70; + lights, 0; + + /* Initialise display */ Display_Init(); - printf("PRINTING LIGHT LEVEL\r\n"); + printf("LIGHT LEVEL CONTROL\r\n"); + lightStatus = false; GUI_SetFont(GUI_FONT_D80); GUI_SetColor(GUI_BLUE); @@ -45,6 +59,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);