![](/media/cache/profiles/20200518_163046.jpg.50x50_q85.jpg)
TFT supercomputer display simulation using emwin graphics library for PSoC6 pioneer kit
Diff: main.cpp
- Revision:
- 8:3d6af4ab3907
- Parent:
- 7:db53b8fbac48
diff -r db53b8fbac48 -r 3d6af4ab3907 main.cpp --- a/main.cpp Wed Oct 27 22:51:42 2021 +0000 +++ b/main.cpp Mon May 23 14:20:15 2022 +0000 @@ -14,6 +14,9 @@ #define LED_ON (1) #define TITLE_OFFSET (16+LED_RADIUS) #undef COLOURED_LEDS +//#define RED_FADE 1 +//#define GREEN_FADE 1 +//#define BLUE_FADE 1 void Display_Init(void) { @@ -39,55 +42,63 @@ printf("Starting Supercomputer\r\n"); GUI_SetFont(GUI_FONT_8X16X2X2); -// GUI_SetColor(GUI_DARKGREEN); + + bool RED_FADE = 0; + bool GREEN_FADE = 1; + bool BLUE_FADE = 0; uint32_t array[NUMLEDS_X][NUMLEDS_Y]; + uint32_t shade; + int32_t decrement = 0x41; + for (int j=0; j < NUMLEDS_Y; j++) { for (int i=0; i < NUMLEDS_X; i++) { - array[i][j]=GUI_GREEN; - GUI_SetColor(GUI_GREEN); -// GUI_DrawCircle(LED_RADIUS+(i)*LED_DIAMETER, TITLE_OFFSET+(j*LED_DIAMETER), LED_RADIUS); + array[i][j]=(RED_FADE?0x04ff0000:0)|(GREEN_FADE?0x0200ff00:0)|(BLUE_FADE?0x010000ff:0); + GUI_SetColor((array[i][j])&0x00ffffff); } } while(1) { int ledx = rand()%NUMLEDS_X; int ledy = rand()%NUMLEDS_Y; - array[ledx][ledy] = (array[ledx][ledy] - 0x00000800)&0x0000FC00; // dim the led - if ((array[ledx][ledy]&0xFF00)==0) { -#ifdef COLOURED_LEDS - uint32_t colour = rand()%4; - switch(colour) { - case 0: - GUI_SetColor(GUI_LIGHTBLUE); - array[ledx][ledy] = GUI_LIGHTBLUE; - break; - case 1: - GUI_SetColor(GUI_LIGHTGREEN); - array[ledx][ledy] = GUI_LIGHTGREEN; - break; - case 2: - array[ledx][ledy] = GUI_LIGHTRED; - GUI_SetColor(GUI_LIGHTRED); - break; - default: - GUI_SetColor(GUI_YELLOW); - array[ledx][ledy] = GUI_YELLOW|0x808080; - break; - } -#else - GUI_SetColor(GUI_GREEN); -#endif - GUI_FillCircle(LED_RADIUS+(ledx)*LED_DIAMETER, TITLE_OFFSET+LED_DIAMETER*(ledy), LED_RADIUS); -// array[ledx][ledy] = LED_ON; + + if ((array[ledx][ledy])&0x04000000) { // dim Blue + shade = ((array[ledx][ledy])>>16)&0xff; + if (array[ledx][ledy]&0x08000000) shade = (shade + decrement) & 0xfc; + else shade = (shade - decrement) & 0xfc; + array[ledx][ledy]=(array[ledx][ledy])&0xff00ffff; + shade = shade << 16; + array[ledx][ledy] = shade + array[ledx][ledy]; + } + if ((array[ledx][ledy])&0x02000000) { // dim Green + shade = ((array[ledx][ledy])>>8)&0xff; + if (array[ledx][ledy]&0x08000000) shade = (shade + decrement) & 0xfc; + else shade = (shade - decrement) & 0xfc; + array[ledx][ledy]=(array[ledx][ledy])&0xffff00ff; + shade = shade << 8; + array[ledx][ledy] = (uint32_t)shade + (uint32_t)array[ledx][ledy]; + } + if ((array[ledx][ledy])&0x01000000) { // dim Red + shade = (array[ledx][ledy])&0xff; + if (array[ledx][ledy]&0x08000000) shade = (shade + decrement) & 0xfc; + else shade = (shade - decrement) & 0xfc; + array[ledx][ledy]=(array[ledx][ledy])&0xffffff00; + array[ledx][ledy] = (array[ledx][ledy] + shade); + } + + + if ((array[ledx][ledy]&0x00ffffff)==0) { + if ((array[ledx][ledy]&0x08000000)) array[ledx][ledy] = (array[ledx][ledy]^0x08000000); + else array[ledx][ledy] = (array[ledx][ledy]^0x08000000)^((rand()%2)?0x04000000:0)^((rand()%2)?0x02000000:0)^((rand()%2)?0x01000000:0); +// uint32_t currentColour =(RED_FADE?0x00ff0000:0)|(GREEN_FADE?0x0000ff00:0)|(BLUE_FADE?0x000000ff:0); +// GUI_SetColor(currentColour); +// GUI_FillCircle(LED_RADIUS+(ledx)*LED_DIAMETER, TITLE_OFFSET+LED_DIAMETER*(ledy), LED_RADIUS); } else { -// array[ledx][ledy]=array[ledx][ledy] >> 1; // dim the led - GUI_SetColor(array[ledx][ledy]); + shade = (array[ledx][ledy])&0x00ffffff; + GUI_SetColor(shade); GUI_FillCircle(LED_RADIUS+(ledx)*LED_DIAMETER, TITLE_OFFSET+LED_DIAMETER*(ledy), LED_RADIUS); + if ((ledx==0)&&(ledy==0)) + printf("%08x\n", array[ledx][ledy]); -// GUI_SetColor(GUI_DARKGREEN); -// GUI_DrawCircle(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; } } }