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.
Revision 6:e85892436f70, committed 2021-11-03
- Comitter:
- 10740761
- Date:
- Wed Nov 03 11:50:38 2021 +0000
- Parent:
- 5:25c7ff9c9085
- Child:
- 7:5e220d3e8a94
- Commit message:
- light sensor v2; ;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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;
- }
- }
+
}