Template for working forward

Dependencies:   mbed PinDetect

Committer:
reedas
Date:
Sun Oct 17 18:29:13 2021 +0000
Revision:
4:d129442ea4dd
Parent:
3:a14b2aa7546e
Child:
5:a7f8c11020f7
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
reedas 2:ad262f2c84ca 1 /* Hello World! for the Emwin TFT Library */
reedas 1:402b32a1025f 2
romilly 0:6beb6f498640 3 #include "mbed.h"
reedas 1:402b32a1025f 4 #include "GUI.h"
reedas 1:402b32a1025f 5 #include "cy8ckit_028_tft.h"
reedas 2:ad262f2c84ca 6
reedas 4:d129442ea4dd 7 #define LED_DIAMETER (16)
reedas 4:d129442ea4dd 8 #define LED_RADIUS (LED_DIAMETER/2)
reedas 4:d129442ea4dd 9 #define DISPLAY_X (320)
reedas 4:d129442ea4dd 10 #define DISPLAY_Y (240)
reedas 4:d129442ea4dd 11 #define NUMLEDS_X (DISPLAY_X/LED_DIAMETER)
reedas 4:d129442ea4dd 12 #define NUMLEDS_Y (DISPLAY_Y/LED_DIAMETER)
reedas 4:d129442ea4dd 13 #define LED_OFF (0)
reedas 4:d129442ea4dd 14 #define LED_ON (1)
reedas 4:d129442ea4dd 15 #define TITLE_OFFSET (16+LED_RADIUS)
reedas 1:402b32a1025f 16
reedas 1:402b32a1025f 17 void Display_Init(void)
reedas 1:402b32a1025f 18 {
reedas 4:d129442ea4dd 19 /* Initialise EmWin driver*/
reedas 4:d129442ea4dd 20 GUI_Init();
reedas 1:402b32a1025f 21
reedas 1:402b32a1025f 22 /* Set font size, foreground and background Colours */
reedas 1:402b32a1025f 23 GUI_SetFont(GUI_FONT_16B_1);
reedas 1:402b32a1025f 24 GUI_SetColor(GUI_WHITE);
reedas 1:402b32a1025f 25 GUI_SetBkColor(GUI_BLACK);
romilly 0:6beb6f498640 26
reedas 1:402b32a1025f 27 /* Clear screen and print splash screen */
reedas 1:402b32a1025f 28 GUI_Clear();
reedas 1:402b32a1025f 29 GUI_SetTextAlign(GUI_TA_HCENTER);
reedas 4:d129442ea4dd 30 GUI_DispStringAt("asr666 Super Computer", 160, 0);
reedas 1:402b32a1025f 31 }
reedas 1:402b32a1025f 32
reedas 1:402b32a1025f 33 int main()
reedas 1:402b32a1025f 34 {
reedas 1:402b32a1025f 35 /* Initialise display */
reedas 1:402b32a1025f 36 Display_Init();
reedas 2:ad262f2c84ca 37
reedas 4:d129442ea4dd 38 printf("Starting Supercomputer\r\n");
reedas 1:402b32a1025f 39
reedas 1:402b32a1025f 40 GUI_SetFont(GUI_FONT_8X16X2X2);
reedas 4:d129442ea4dd 41 GUI_SetColor(GUI_DARKGREEN);
reedas 4:d129442ea4dd 42 uint8_t array[NUMLEDS_X][NUMLEDS_Y];
reedas 4:d129442ea4dd 43 for (int j=0; j < NUMLEDS_Y; j++) {
reedas 4:d129442ea4dd 44 for (int i=0; i < NUMLEDS_X; i++) {
reedas 4:d129442ea4dd 45 array[i][j]=LED_OFF;
reedas 4:d129442ea4dd 46 GUI_SetColor(GUI_DARKGREEN);
reedas 4:d129442ea4dd 47 GUI_FillCircle(LED_RADIUS+(i)*LED_DIAMETER, TITLE_OFFSET+(j*LED_DIAMETER), LED_RADIUS);
reedas 4:d129442ea4dd 48 }
reedas 4:d129442ea4dd 49 }
reedas 2:ad262f2c84ca 50 while(1) {
reedas 4:d129442ea4dd 51 int ledx = rand()%NUMLEDS_X;
reedas 4:d129442ea4dd 52 int ledy = rand()%NUMLEDS_Y;
reedas 4:d129442ea4dd 53 if (array[ledx][ledy]==LED_OFF) {
reedas 4:d129442ea4dd 54 GUI_SetColor(GUI_GREEN);
reedas 4:d129442ea4dd 55 GUI_FillCircle(LED_RADIUS+(ledx)*LED_DIAMETER, TITLE_OFFSET+LED_DIAMETER*(ledy), LED_RADIUS);
reedas 4:d129442ea4dd 56 array[ledx][ledy] = LED_ON;
reedas 3:a14b2aa7546e 57 }
reedas 4:d129442ea4dd 58 else {
reedas 4:d129442ea4dd 59 GUI_SetColor(GUI_DARKGREEN);
reedas 4:d129442ea4dd 60 GUI_FillCircle(LED_RADIUS+(ledx)*LED_DIAMETER, TITLE_OFFSET+LED_DIAMETER*(ledy), LED_RADIUS);
reedas 4:d129442ea4dd 61 // GUI_FillCircle(8+(ledx)*16, 24+16*(ledy), 8);
reedas 4:d129442ea4dd 62 array[ledx][ledy] = LED_OFF;
reedas 4:d129442ea4dd 63 }
reedas 2:ad262f2c84ca 64 }
romilly 0:6beb6f498640 65 }
reedas 1:402b32a1025f 66
reedas 1:402b32a1025f 67
reedas 1:402b32a1025f 68