Personal Test Environment

Dependencies:   LCD_DISCO_F746NG TS_DISCO_F746NG mbed

drawMe.h

Committer:
DirtyGray
Date:
2018-03-06
Revision:
0:bab80a319f0d

File content as of revision 0:bab80a319f0d:

void drawGame()
{
//INITIATE LCD SCREEN
    LCD_DISCO_F746NG LCDscreen;
    TS_DISCO_F746NG LCDtouchScreen;
    TS_StateTypeDef touchStatus;
    LCDtouchScreen.Init(480, 272);

//DECLARE VARIABLES
    int circleDiameter = 5;
    int counter = 0;
    int screenColor = 1;
//unsigned short xPrint;
//unsigned short yPrint;

//SET LCD SCREEN
    LCDscreen.Clear(LCD_COLOR_BLACK);
    LCDscreen.SetBackColor(LCD_COLOR_BLACK);
    wait(1);

    while(1) {
//CLEAR THE SCREEN AND DRAW THE CIRCLES
        LCDscreen.Clear(LCD_COLOR_BLACK);
        LCDscreen.SetTextColor(LCD_COLOR_BLUE);
        LCDscreen.FillCircle(20, 20, 20);
        LCDscreen.SetTextColor(LCD_COLOR_RED);
        LCDscreen.FillCircle(20, 60, 20);
        LCDscreen.SetTextColor(LCD_COLOR_YELLOW);
        LCDscreen.FillCircle(20, 100, 20);
        LCDscreen.SetTextColor(LCD_COLOR_GREEN);
        LCDscreen.FillCircle(20, 140, 20);
        LCDscreen.SetTextColor(LCD_COLOR_WHITE);
        LCDscreen.FillCircle(20, 180, 20);
        LCDscreen.SetTextColor(LCD_COLOR_SADDLE_BROWN);
        LCDscreen.FillCircle(20, 220, 20);

//WHILE COUNTER IS INCRIMENTING, CHECK FOR INPUT AND DRAW CIRCLE WHERE TOUCH IS
        while(counter < 10000) {
            switch (screenColor) {
                case 1:
                    LCDscreen.SetTextColor(LCD_COLOR_BLUE);
                    break;
                case 2:
                    LCDscreen.SetTextColor(LCD_COLOR_RED);
                    break;
                case 3:
                    LCDscreen.SetTextColor(LCD_COLOR_YELLOW);
                    break;
                case 4:
                    LCDscreen.SetTextColor(LCD_COLOR_GREEN);
                    break;
                case 5:
                    LCDscreen.SetTextColor(LCD_COLOR_WHITE);
                    break;
                case 6:
                    LCDscreen.SetTextColor(LCD_COLOR_SADDLE_BROWN);
                    break;
            }

            LCDtouchScreen.GetState(&touchStatus);
            if (touchStatus.touchDetected) {
                if ((touchStatus.touchX[0] <= 40) && (touchStatus.touchY[0] <= 40))
                    screenColor = 1;
                else if ((touchStatus.touchX[0] <= 40) && (touchStatus.touchY[0] >= 40) && (touchStatus.touchY[0] <= 80))
                    screenColor = 2;
                else if ((touchStatus.touchX[0] <= 40) && (touchStatus.touchY[0] >= 80) && (touchStatus.touchY[0] <= 120))
                    screenColor = 3;
                else if ((touchStatus.touchX[0] <= 40) && (touchStatus.touchY[0] >= 120) && (touchStatus.touchY[0] <= 160))
                    screenColor = 4;
                else if ((touchStatus.touchX[0] <= 40) && (touchStatus.touchY[0] >= 160) && (touchStatus.touchY[0] <= 200))
                    screenColor = 5;
                else if ((touchStatus.touchX[0] <= 40) && (touchStatus.touchY[0] >= 200) && (touchStatus.touchY[0] <= 240))
                    screenColor = 6;
                if (touchStatus.touchY[0] < circleDiameter)
                    counter = 0;
                else if (touchStatus.touchX[0] > (480 - circleDiameter))
                    counter = 0;
                else if (touchStatus.touchX[0] < circleDiameter)
                    counter = 0;
                else if (touchStatus.touchY[0] > (272 - circleDiameter))
                    counter = 0;
                else {
                    LCDscreen.FillCircle(touchStatus.touchX[0], touchStatus.touchY[0], circleDiameter);
                    counter = 0;
                    // xPrint = touchStatus.touchX[0];
                    // yPrint = touchStatus.touchY[0];
                    // printf("%hu %hu", xPrint, yPrint);
                }
            } else {
                counter++;
            }
        }
        counter = 0;
    }
}