Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* Hello World! for the Emwin TFT Library */ 00002 00003 #include "mbed.h" 00004 #include "GUI.h" 00005 #include "cy8ckit_028_tft.h" 00006 00007 #define LED_DIAMETER (8) 00008 #define LED_RADIUS (LED_DIAMETER/2) 00009 #define DISPLAY_X (320) 00010 #define DISPLAY_Y (240) 00011 #define NUMLEDS_X (DISPLAY_X/LED_DIAMETER) 00012 #define NUMLEDS_Y (DISPLAY_Y/LED_DIAMETER) 00013 #define LED_OFF (0) 00014 #define LED_ON (1) 00015 #define TITLE_OFFSET (16+LED_RADIUS) 00016 00017 AnalogIn lightlevel(P10_0); 00018 DigitalOut lights(LED4); 00019 DigitalOut lightsR(LED1); 00020 DigitalOut lightsG(LED3); 00021 DigitalOut lightsB(LED2); 00022 00023 00024 bool lightStatus; 00025 00026 void Display_Init(void) 00027 { 00028 /* Initialise EmWin driver*/ 00029 GUI_Init(); 00030 00031 /* Set font size, foreground and background Colours */ 00032 GUI_SetFont(GUI_FONT_24B_1); 00033 GUI_SetColor(GUI_WHITE); 00034 GUI_SetBkColor(GUI_BLACK); 00035 00036 /* Clear screen and print splash screen */ 00037 GUI_Clear(); 00038 GUI_SetTextAlign(GUI_TA_HCENTER); 00039 GUI_DispStringAt("LIGHT SENSOR", 160, 0); 00040 } 00041 00042 int main() 00043 { 00044 int lowThresh, highThresh; 00045 lowThresh = 40; 00046 highThresh = 70; 00047 lights, 0; 00048 00049 00050 /* Initialise display */ 00051 Display_Init(); 00052 00053 printf("LIGHT LEVEL CONTROL\r\n"); 00054 lightStatus = false; 00055 00056 GUI_SetFont(GUI_FONT_D80); 00057 GUI_SetColor(GUI_BLUE); 00058 while(true){ 00059 int lightpercent; 00060 lightpercent = (lightlevel.read_u16()*100)/65535; 00061 printf("light level is %d\r\n", lightpercent); 00062 if(lightpercent > highThresh) lightStatus = 1; 00063 else if(lightpercent < lowThresh) lightStatus = 0; 00064 lights = lightStatus; 00065 if(lightpercent > highThresh) { 00066 lightsB = 0; 00067 lightsR = 1; 00068 lightsG = 1; 00069 } 00070 if(lightpercent < highThresh && lightpercent > lowThresh) { 00071 lightsB = 1; 00072 lightsR = 1; 00073 lightsG = 0; 00074 } 00075 if(lightpercent < lowThresh) { 00076 lightsB = 1; 00077 lightsR = 0; 00078 lightsG = 1; 00079 } 00080 00081 ThisThread::sleep_for(1000); 00082 char buffer[16]; 00083 sprintf(buffer, "%d", lightpercent); 00084 GUI_DispStringAt(buffer, 30, 30); 00085 GUI_SetColor(GUI_DARKGREEN); 00086 GUI_FillRect(260, 30, 300, 220); 00087 GUI_SetColor(GUI_GREEN); 00088 GUI_FillRect(260, 220 - lightpercent * 2, 300, 220); 00089 00090 } 00091 00092 } 00093 00094 00095
Generated on Mon Aug 1 2022 17:37:43 by
1.7.2