![](/media/cache/profiles/20200518_163046.jpg.50x50_q85.jpg)
TFT supercomputer display simulation using emwin graphics library for PSoC6 pioneer kit
main.cpp@7:db53b8fbac48, 2021-10-27 (annotated)
- Committer:
- reedas
- Date:
- Wed Oct 27 22:51:42 2021 +0000
- Revision:
- 7:db53b8fbac48
- Parent:
- 6:f546a5504ac0
- Child:
- 8:3d6af4ab3907
Fading Green only
Who changed what in which revision?
User | Revision | Line number | New 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 | 6:f546a5504ac0 | 15 | #define TITLE_OFFSET (16+LED_RADIUS) |
reedas | 6:f546a5504ac0 | 16 | #undef COLOURED_LEDS |
reedas | 1:402b32a1025f | 17 | |
reedas | 1:402b32a1025f | 18 | void Display_Init(void) |
reedas | 1:402b32a1025f | 19 | { |
reedas | 4:d129442ea4dd | 20 | /* Initialise EmWin driver*/ |
reedas | 4:d129442ea4dd | 21 | GUI_Init(); |
reedas | 1:402b32a1025f | 22 | |
reedas | 1:402b32a1025f | 23 | /* Set font size, foreground and background Colours */ |
reedas | 1:402b32a1025f | 24 | GUI_SetFont(GUI_FONT_16B_1); |
reedas | 1:402b32a1025f | 25 | GUI_SetColor(GUI_WHITE); |
reedas | 1:402b32a1025f | 26 | GUI_SetBkColor(GUI_BLACK); |
romilly | 0:6beb6f498640 | 27 | |
reedas | 1:402b32a1025f | 28 | /* Clear screen and print splash screen */ |
reedas | 1:402b32a1025f | 29 | GUI_Clear(); |
reedas | 1:402b32a1025f | 30 | GUI_SetTextAlign(GUI_TA_HCENTER); |
reedas | 5:024a2880721e | 31 | GUI_DispStringAt("CITY3032 Super Computer", 160, 0); |
reedas | 1:402b32a1025f | 32 | } |
reedas | 1:402b32a1025f | 33 | |
reedas | 1:402b32a1025f | 34 | int main() |
reedas | 1:402b32a1025f | 35 | { |
reedas | 1:402b32a1025f | 36 | /* Initialise display */ |
reedas | 1:402b32a1025f | 37 | Display_Init(); |
reedas | 2:ad262f2c84ca | 38 | |
reedas | 4:d129442ea4dd | 39 | printf("Starting Supercomputer\r\n"); |
reedas | 1:402b32a1025f | 40 | |
reedas | 1:402b32a1025f | 41 | GUI_SetFont(GUI_FONT_8X16X2X2); |
reedas | 6:f546a5504ac0 | 42 | // GUI_SetColor(GUI_DARKGREEN); |
reedas | 6:f546a5504ac0 | 43 | uint32_t array[NUMLEDS_X][NUMLEDS_Y]; |
reedas | 4:d129442ea4dd | 44 | for (int j=0; j < NUMLEDS_Y; j++) { |
reedas | 4:d129442ea4dd | 45 | for (int i=0; i < NUMLEDS_X; i++) { |
reedas | 7:db53b8fbac48 | 46 | array[i][j]=GUI_GREEN; |
reedas | 7:db53b8fbac48 | 47 | GUI_SetColor(GUI_GREEN); |
reedas | 6:f546a5504ac0 | 48 | // GUI_DrawCircle(LED_RADIUS+(i)*LED_DIAMETER, TITLE_OFFSET+(j*LED_DIAMETER), LED_RADIUS); |
reedas | 4:d129442ea4dd | 49 | } |
reedas | 4:d129442ea4dd | 50 | } |
reedas | 2:ad262f2c84ca | 51 | while(1) { |
reedas | 4:d129442ea4dd | 52 | int ledx = rand()%NUMLEDS_X; |
reedas | 4:d129442ea4dd | 53 | int ledy = rand()%NUMLEDS_Y; |
reedas | 7:db53b8fbac48 | 54 | array[ledx][ledy] = (array[ledx][ledy] - 0x00000800)&0x0000FC00; // dim the led |
reedas | 7:db53b8fbac48 | 55 | if ((array[ledx][ledy]&0xFF00)==0) { |
reedas | 6:f546a5504ac0 | 56 | #ifdef COLOURED_LEDS |
reedas | 6:f546a5504ac0 | 57 | uint32_t colour = rand()%4; |
reedas | 5:024a2880721e | 58 | switch(colour) { |
reedas | 5:024a2880721e | 59 | case 0: |
reedas | 6:f546a5504ac0 | 60 | GUI_SetColor(GUI_LIGHTBLUE); |
reedas | 6:f546a5504ac0 | 61 | array[ledx][ledy] = GUI_LIGHTBLUE; |
reedas | 5:024a2880721e | 62 | break; |
reedas | 5:024a2880721e | 63 | case 1: |
reedas | 6:f546a5504ac0 | 64 | GUI_SetColor(GUI_LIGHTGREEN); |
reedas | 6:f546a5504ac0 | 65 | array[ledx][ledy] = GUI_LIGHTGREEN; |
reedas | 5:024a2880721e | 66 | break; |
reedas | 5:024a2880721e | 67 | case 2: |
reedas | 6:f546a5504ac0 | 68 | array[ledx][ledy] = GUI_LIGHTRED; |
reedas | 6:f546a5504ac0 | 69 | GUI_SetColor(GUI_LIGHTRED); |
reedas | 5:024a2880721e | 70 | break; |
reedas | 6:f546a5504ac0 | 71 | default: |
reedas | 5:024a2880721e | 72 | GUI_SetColor(GUI_YELLOW); |
reedas | 6:f546a5504ac0 | 73 | array[ledx][ledy] = GUI_YELLOW|0x808080; |
reedas | 5:024a2880721e | 74 | break; |
reedas | 5:024a2880721e | 75 | } |
reedas | 6:f546a5504ac0 | 76 | #else |
reedas | 7:db53b8fbac48 | 77 | GUI_SetColor(GUI_GREEN); |
reedas | 6:f546a5504ac0 | 78 | #endif |
reedas | 4:d129442ea4dd | 79 | GUI_FillCircle(LED_RADIUS+(ledx)*LED_DIAMETER, TITLE_OFFSET+LED_DIAMETER*(ledy), LED_RADIUS); |
reedas | 6:f546a5504ac0 | 80 | // array[ledx][ledy] = LED_ON; |
reedas | 3:a14b2aa7546e | 81 | } |
reedas | 4:d129442ea4dd | 82 | else { |
reedas | 6:f546a5504ac0 | 83 | // array[ledx][ledy]=array[ledx][ledy] >> 1; // dim the led |
reedas | 6:f546a5504ac0 | 84 | GUI_SetColor(array[ledx][ledy]); |
reedas | 4:d129442ea4dd | 85 | GUI_FillCircle(LED_RADIUS+(ledx)*LED_DIAMETER, TITLE_OFFSET+LED_DIAMETER*(ledy), LED_RADIUS); |
reedas | 5:024a2880721e | 86 | |
reedas | 5:024a2880721e | 87 | // GUI_SetColor(GUI_DARKGREEN); |
reedas | 5:024a2880721e | 88 | // GUI_DrawCircle(LED_RADIUS+(ledx)*LED_DIAMETER, TITLE_OFFSET+LED_DIAMETER*(ledy), LED_RADIUS); |
reedas | 4:d129442ea4dd | 89 | // GUI_FillCircle(8+(ledx)*16, 24+16*(ledy), 8); |
reedas | 6:f546a5504ac0 | 90 | // array[ledx][ledy] = LED_OFF; |
reedas | 4:d129442ea4dd | 91 | } |
reedas | 2:ad262f2c84ca | 92 | } |
romilly | 0:6beb6f498640 | 93 | } |
reedas | 1:402b32a1025f | 94 | |
reedas | 1:402b32a1025f | 95 | |
reedas | 1:402b32a1025f | 96 |