![](/media/cache/profiles/20200518_163046.jpg.50x50_q85.jpg)
Template for working forward
Diff: main.cpp
- Revision:
- 4:d129442ea4dd
- Parent:
- 3:a14b2aa7546e
- Child:
- 5:9a03cb84a60c
--- a/main.cpp Sat Oct 16 22:44:39 2021 +0000 +++ b/main.cpp Sun Oct 17 18:29:13 2021 +0000 @@ -3,27 +3,21 @@ #include "mbed.h" #include "GUI.h" #include "cy8ckit_028_tft.h" -#include "PinDetect.h" -PinDetect pb1(SWITCH2); -uint8 counter = 0; -AnalogIn lightLevel(P10_0); -Serial pc(USBTX, USBRX); - -// Callback routine is interrupt activated by a debounced pb1 hit -void pb1_hit_callback (void) -{ - counter = 0; -} - -int readLightLevel() { - int lightPercent; - lightPercent = (lightLevel.read_u16()*100)/65535; - return lightPercent; - } +#define LED_DIAMETER (16) +#define LED_RADIUS (LED_DIAMETER/2) +#define DISPLAY_X (320) +#define DISPLAY_Y (240) +#define NUMLEDS_X (DISPLAY_X/LED_DIAMETER) +#define NUMLEDS_Y (DISPLAY_Y/LED_DIAMETER) +#define LED_OFF (0) +#define LED_ON (1) +#define TITLE_OFFSET (16+LED_RADIUS) void Display_Init(void) { + /* Initialise EmWin driver*/ + GUI_Init(); /* Set font size, foreground and background Colours */ GUI_SetFont(GUI_FONT_16B_1); @@ -33,55 +27,40 @@ /* Clear screen and print splash screen */ GUI_Clear(); GUI_SetTextAlign(GUI_TA_HCENTER); - GUI_DispStringAt("TFT Demo", 160, 20); + GUI_DispStringAt("asr666 Super Computer", 160, 0); } int main() { - - /* Initialise EmWin driver*/ - GUI_Init(); - /* Initialise display */ Display_Init(); - pb1.mode(PullUp); - // Delay for initial pullup to take effect - ThisThread::sleep_for(10); - // Setup Interrupt callback functions for a pb hit - pb1.attach_deasserted(&pb1_hit_callback); - // Start sampling pb inputs using interrupts - pb1.setSampleFrequency(); - pc.printf("tft demo\r\n"); - + printf("Starting Supercomputer\r\n"); GUI_SetFont(GUI_FONT_8X16X2X2); - GUI_SetTextAlign(GUI_TA_HCENTER); - GUI_DispStringAt("Hello World!", 160, 40); + 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); + } + } while(1) { - - GUI_SetTextAlign(GUI_TA_HCENTER); - GUI_DispHexAt(counter, 160, 100, 2); - GUI_SetTextAlign(GUI_TA_HCENTER); - GUI_DispDecAt(counter, 160, 70, 3); - for(int pos = 0; pos < 8; pos++) { - if ((counter >> pos & 0x01) == 1) { - GUI_SetColor(GUI_BLUE); - } - else { - GUI_SetColor(GUI_DARKBLUE); - } -// GUI_FillRect(208 - (16*pos), 140, 224 - (2+16 * pos), 156); - GUI_FillCircle(216 - (16*pos), 148, 8); + 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; } - GUI_SetColor(GUI_WHITE); - GUI_SetTextAlign(GUI_TA_HCENTER); - GUI_DispBinAt(counter++, 160, 160, 8); - GUI_DispStringAt("Light is: ", 40, 200); - GUI_DispDec(readLightLevel(), 3); - GUI_DispString("%"); - ThisThread::sleep_for(500); - + 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; + } } }