void TM_ILI9341_DrawFilledCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) { int16_t f = 1 - r; int16_t ddF_x = 1; int16_t ddF_y = -2 * r; int16_t x = 0; int16_t y = r; TM_ILI9341_DrawPixel(x0, y0 + r, color); TM_ILI9341_DrawPixel(x0, y0 - r, color); TM_ILI9341_DrawPixel(x0 + r, y0, color); TM_ILI9341_DrawPixel(x0 - r, y0, color); TM_ILI9341_DrawLine(x0 - r, y0, x0 + r, y0, color); while (x < y) { if (f >= 0) { y--; ddF_y += 2; f += ddF_y; } x++; ddF_x += 2; f += ddF_x; TM_ILI9341_DrawLine(x0 - x, y0 + y, x0 + x, y0 + y, color); TM_ILI9341_DrawLine(x0 + x, y0 - y, x0 - x, y0 - y, color); TM_ILI9341_DrawLine(x0 + y, y0 + x, x0 - y, y0 + x, color); TM_ILI9341_DrawLine(x0 + y, y0 - x, x0 - y, y0 - x, color); } }
void TM_ILI9341_DrawFilledBrokenCircle (int poX, int poY, int r, uint16_t color) { //int poX = -100; // int poY = 120; //int r = 150; int x = -r, y = 0, err = 2-2*r, e2; do { uint8_t draw = 1; int x_min_x = poX-x; if (poX-x < 0) draw = 0; //x_min_x = 0; int y_min_y = poY-y; if (poY-y < 0) y_min_y = 0; int x_plus_x = poX+x; if (x_plus_x > 320) draw = 0; //x_plus_x = 320; int hght = y_min_y+2*y; if (hght > 240) hght = 240; if (draw) { //drawVerticalLine(poX-x, poY-y, 2*y, color); TM_ILI9341_DrawLine(x_min_x, y_min_y, x_min_x, hght, color); //drawVerticalLine(poX+x, poY-y, 2*y, color); if (x_plus_x > 0) TM_ILI9341_DrawLine(x_plus_x, y_min_y, x_plus_x, hght, color); } e2 = err; if (e2 <= y) { err += ++y*2+1; if (-x == y && e2 <= x) e2 = 0; } if (e2 > x) err += ++x*2+1; } while (x <= 0); }
int main(void) { /* Initialize system */ SystemInit(); /* Initialize ILI9341 */ TM_ILI9341_Init(); /* Rotate LCD for 90 degrees */ TM_ILI9341_Rotate(TM_ILI9341_Orientation_Landscape_2); /* Fill lcd with color */ TM_ILI9341_Fill(ILI9341_COLOR_MAGENTA); /* Draw white circle */ TM_ILI9341_DrawCircle(60, 60, 40, ILI9341_COLOR_GREEN); /* Draw red filled circle */ TM_ILI9341_DrawFilledCircle(60, 60, 35, ILI9341_COLOR_RED); /* Draw blue rectangle */ TM_ILI9341_DrawRectangle(120, 20, 220, 100, ILI9341_COLOR_BLUE); /* Draw black filled circle */ TM_ILI9341_DrawFilledRectangle(130, 30, 210, 90, ILI9341_COLOR_BLACK); /* Draw line with custom color 0x0005 */ TM_ILI9341_DrawLine(10, 120, 310, 120, 0x0005); /* Put string with black foreground color and blue background with 11x18px font */ TM_ILI9341_Puts(65, 130, "STM32F4 Discovery", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2); /* Put string with black foreground color and blue background with 11x18px font */ TM_ILI9341_Puts(60, 150, "ILI9341 LCD Module", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2); /* Put string with black foreground color and red background with 11x18px font */ TM_ILI9341_Puts(45, 229, "stm32f4-discovery.com", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); while (1) { } }
void printGraphsLCD(int* accelData, int analogIn) { // Only draw if it is time to do so //if (TM_DELAY_Time() > 1) { mini_snprintf(lcdstr,100,"A:%d___",analogIn); TM_ILI9341_Puts(30, 60, lcdstr, &TM_Font_11x18, ILI9341_COLOR_YELLOW, ILI9341_COLOR_BLACK); // Draw 3 accel graphs on top half of the screen int ax = 80 + accelData[0]*40/4096; int ay = 80 + accelData[1]*40/4096; int az = 80 + accelData[2]*40/4096; TM_ILI9341_DrawLine(xpix,80,xpix+1,80,ILI9341_COLOR_GRAY); TM_ILI9341_DrawLine(xpix,axprev,xpix+1,ax,ILI9341_COLOR_RED); TM_ILI9341_DrawLine(xpix,ayprev,xpix+1,ay,ILI9341_COLOR_GREEN); TM_ILI9341_DrawLine(xpix,azprev,xpix+1,az,ILI9341_COLOR_BLUE); axprev = ax; ayprev = ay; azprev = az; // Draw vertical line TM_ILI9341_DrawLine(1,160,240,160,ILI9341_COLOR_WHITE); // Draw strain graph on bottom half int strain = 180 + analogIn*140/4096; TM_ILI9341_DrawLine(xpix,strainprev,xpix+1,strain,ILI9341_COLOR_CYAN); strainprev = strain; // Move x coord xpix++; if(xpix > 239) { xpix = 1; // Clear whole screen TM_ILI9341_Fill(ILI9341_COLOR_BLACK); } // Reset timer // TM_DELAY_SetTime(0); //} }
void TM_ILI9341_DrawFilledRectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) { for (; y0 < y1; y0++) { TM_ILI9341_DrawLine(x0, y0, x1, y0, color); } }
void TM_ILI9341_DrawRectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) { TM_ILI9341_DrawLine(x0, y0, x1, y0, color); //Top TM_ILI9341_DrawLine(x0, y0, x0, y1, color); //Left TM_ILI9341_DrawLine(x1, y0, x1, y1, color); //Right TM_ILI9341_DrawLine(x0, y1, x1, y1, color); //Bottom }
void ekran(int nr){ switch(nr){ case 1: //Rotate LCD for 90 degrees TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); //FIll lcd with color TM_ILI9341_Fill(ILI9341_COLOR_ORANGE); //Draw white circle //TM_ILI9341_DrawCircle(0, 0, 10, ILI9341_COLOR_GREEN); //Draw red filled circle TM_ILI9341_DrawFilledCircle(60, 40, 35, ILI9341_COLOR_RED); //Draw blue rectangle //TM_ILI9341_DrawRectangle(120, 20, 220, 100, ILI9341_COLOR_BLUE); //Draw black filled rectangle TM_ILI9341_DrawFilledRectangle(70, 200, 160, 240, ILI9341_COLOR_RED); TM_ILI9341_Puts(85, 215, "START", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_RED); //Draw line with custom color 0x0005 TM_ILI9341_DrawLine(20, 120, 220, 120, 0x0005); //Put string with black foreground color and blue background with 11x18px font TM_ILI9341_Puts(40, 110, " STEP DRIVER ", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); //Put string with black foreground color and blue background with 11x18px font TM_ILI9341_Puts(10, 140, "Press START to begin", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); //Put string with black foreground color and red background with 11x18px font TM_ILI9341_Puts(1, 310, "LB", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); return; case 2: //Rotate LCD for 90 degrees TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); //FIll lcd with color TM_ILI9341_Fill(ILI9341_COLOR_BLUE2); //Draw blue rectangle //TM_ILI9341_DrawRectangle(120, 20, 220, 100, ILI9341_COLOR_BLUE); //Draw black filled rectangle TM_ILI9341_DrawFilledRectangle(10, 10, 50, 210, ILI9341_COLOR_WHITE); TM_ILI9341_DrawFilledRectangle(70, 10, 110, 210, ILI9341_COLOR_WHITE); TM_ILI9341_DrawFilledRectangle(130, 10, 170, 210, ILI9341_COLOR_WHITE); TM_ILI9341_DrawFilledRectangle(10, 220, 50, 260, ILI9341_COLOR_RED); TM_ILI9341_Puts(15, 230, "STOP", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_RED); TM_ILI9341_DrawFilledRectangle(70, 220, 110, 260, ILI9341_COLOR_RED); TM_ILI9341_Puts(75, 230, "STOP", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_RED); TM_ILI9341_DrawFilledRectangle(130, 220, 170, 260, ILI9341_COLOR_RED); TM_ILI9341_Puts(135, 230, "STOP", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_RED); TM_ILI9341_DrawFilledRectangle(10, 270, 50, 310, ILI9341_COLOR_YELLOW); TM_ILI9341_Puts(15, 280, "CW", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_YELLOW); TM_ILI9341_DrawFilledRectangle(70, 270, 110, 310, ILI9341_COLOR_YELLOW); TM_ILI9341_Puts(75, 280, "CW", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_YELLOW); TM_ILI9341_DrawFilledRectangle(130, 270, 170, 310, ILI9341_COLOR_YELLOW); TM_ILI9341_Puts(135, 280, "CW", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_YELLOW); TM_ILI9341_DrawFilledRectangle(180, 100, 235, 125, ILI9341_COLOR_BLUE); TM_ILI9341_Puts(185, 105, "FULL", &TM_Font_11x18, ILI9341_COLOR_WHITE, ILI9341_COLOR_BLUE); TM_ILI9341_DrawFilledRectangle(180, 130, 235, 155, ILI9341_COLOR_WHITE); TM_ILI9341_Puts(185, 135, "1/2", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_WHITE); TM_ILI9341_DrawFilledRectangle(180, 160, 235, 185, ILI9341_COLOR_WHITE); TM_ILI9341_Puts(185, 165, "1/4", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_WHITE); TM_ILI9341_DrawFilledRectangle(180, 190, 235, 215, ILI9341_COLOR_WHITE); TM_ILI9341_Puts(185, 195, "1/8", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_WHITE); TM_ILI9341_DrawFilledRectangle(180, 220, 235, 245, ILI9341_COLOR_WHITE); TM_ILI9341_Puts(185, 225, "1/16", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_WHITE); TM_ILI9341_DrawFilledRectangle(180, 260, 235, 315, ILI9341_COLOR_MAGENTA); TM_ILI9341_Puts(185, 280, "DOWN", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_MAGENTA); return; default: //Rotate LCD for 90 degrees TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); //FIll lcd with color TM_ILI9341_Fill(ILI9341_COLOR_GREEN); //Draw white circle //TM_ILI9341_DrawCircle(0, 0, 10, ILI9341_COLOR_GREEN); //Draw red filled circle TM_ILI9341_DrawFilledCircle(60, 60, 35, ILI9341_COLOR_RED); //Draw blue rectangle //TM_ILI9341_DrawRectangle(120, 20, 220, 100, ILI9341_COLOR_BLUE); //Draw black filled rectangle TM_ILI9341_DrawFilledRectangle(120, 200, 220, 230, ILI9341_COLOR_RED); return; } }