![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TEMPLATE light sensor 2
Diff: main.cpp
- Revision:
- 6:e85892436f70
- Parent:
- 5:25c7ff9c9085
- Child:
- 7:5e220d3e8a94
diff -r 25c7ff9c9085 -r e85892436f70 main.cpp --- a/main.cpp Wed Oct 20 11:36:51 2021 +0000 +++ b/main.cpp Wed Nov 03 11:50:38 2021 +0000 @@ -12,7 +12,9 @@ #define NUMLEDS_Y (DISPLAY_Y/LED_DIAMETER) #define LED_OFF (0) #define LED_ON (1) -#define TITLE_OFFSET (16+LED_RADIUS) +#define TITLE_OFFSET (16+LED_RADIUS) + +AnalogIn lightlevel(P10_0); void Display_Init(void) { @@ -20,14 +22,14 @@ GUI_Init(); /* Set font size, foreground and background Colours */ - GUI_SetFont(GUI_FONT_16B_1); + GUI_SetFont(GUI_FONT_24B_1); GUI_SetColor(GUI_WHITE); GUI_SetBkColor(GUI_BLACK); /* Clear screen and print splash screen */ GUI_Clear(); GUI_SetTextAlign(GUI_TA_HCENTER); - GUI_DispStringAt("CONNECTION TO NSA SERVER TERMINATED", 160, 0); + GUI_DispStringAt("LIGHT SENSOR", 160, 0); } int main() @@ -35,33 +37,18 @@ /* Initialise display */ Display_Init(); - printf("Starting Supercomputer\r\n"); + printf("PRINTING LIGHT LEVEL\r\n"); - GUI_SetFont(GUI_FONT_8X16X2X2); - GUI_SetColor(GUI_DARKGREEN); - uint8_t array[NUMLEDS_X][NUMLEDS_Y]; - for (int j=0; j < NUMLEDS_Y; j++) { - for (int i=0; i < NUMLEDS_X; i++) { - array[i][j]=LED_OFF; - GUI_SetColor(GUI_DARKGREEN); - GUI_FillCircle(LED_RADIUS+(i)*LED_DIAMETER, TITLE_OFFSET+(j*LED_DIAMETER), LED_RADIUS); + GUI_SetFont(GUI_FONT_24B_1); + GUI_SetColor(GUI_WHITE); + while(true){ + int lightpercent; + lightpercent = (lightlevel.read_u16()*100)/65535; + printf("light level is %d\r\n", lightpercent); + ThisThread::sleep_for(1000); + } - } - while(1) { - int ledx = rand()%NUMLEDS_X; - int ledy = rand()%NUMLEDS_Y; - if (array[ledx][ledy]==LED_OFF) { - GUI_SetColor(GUI_GREEN); - GUI_FillCircle(LED_RADIUS+(ledx)*LED_DIAMETER, TITLE_OFFSET+LED_DIAMETER*(ledy), LED_RADIUS); - array[ledx][ledy] = LED_ON; - } - else { - GUI_SetColor(GUI_DARKGREEN); - GUI_FillCircle(LED_RADIUS+(ledx)*LED_DIAMETER, TITLE_OFFSET+LED_DIAMETER*(ledy), LED_RADIUS); -// GUI_FillCircle(8+(ledx)*16, 24+16*(ledy), 8); - array[ledx][ledy] = LED_OFF; - } - } + }