A simple Pong game with STM32F407VET6 black board (Seeed Arch Max) and ILI9341 320x240 TFT display.

Dependencies:   mbed ILI9341_STM32F4

A simple Pong game with STM32F407VET6 black board (compatible with Seed Arch Max) and ILI9341 320x240 TFT display.

Connect the SPI interface of an ILI9341 320x240 TFT display to the STM32F407VET6 board (Seeed Arch Max) as follows:

ILI9341 TFTSPI interfaceSTM32F407VET6
VCC+5V
GNDGND
CSPB_7
RESETPB_8
D/CPB_6
SDI(MOSI)PB_5
SCKPB_3
LEDover a 56 ohm resistor+5V
SDO(MISO)PB_4
Committer:
hudakz
Date:
Mon Apr 15 06:02:55 2019 +0000
Revision:
1:971e721f6ef2
Parent:
0:887dd664eca0
Simple pong game updated.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:887dd664eca0 1 #include "Racket.h"
hudakz 0:887dd664eca0 2
hudakz 0:887dd664eca0 3 /**
hudakz 0:887dd664eca0 4 * @brief
hudakz 0:887dd664eca0 5 * @note
hudakz 0:887dd664eca0 6 * @param
hudakz 0:887dd664eca0 7 * @retval
hudakz 0:887dd664eca0 8 */
hudakz 0:887dd664eca0 9 Racket::Racket(int w /*= 20*/, int h /*= 40*/, uint16_t clr /*= TFT_WHITE*/ ) :
hudakz 1:971e721f6ef2 10 width(w),
hudakz 1:971e721f6ef2 11 height(h),
hudakz 1:971e721f6ef2 12 xPos(320),
hudakz 1:971e721f6ef2 13 yPos(240 / 2),
hudakz 1:971e721f6ef2 14 yPosOld(240 / 2),
hudakz 1:971e721f6ef2 15 velocity(4),
hudakz 1:971e721f6ef2 16 xDir(0),
hudakz 1:971e721f6ef2 17 yDir(0),
hudakz 1:971e721f6ef2 18 color(clr)
hudakz 0:887dd664eca0 19 { }
hudakz 0:887dd664eca0 20
hudakz 0:887dd664eca0 21 /**
hudakz 0:887dd664eca0 22 * @brief
hudakz 0:887dd664eca0 23 * @note
hudakz 0:887dd664eca0 24 * @param
hudakz 0:887dd664eca0 25 * @retval
hudakz 0:887dd664eca0 26 */
hudakz 1:971e721f6ef2 27 void Racket::home()
hudakz 1:971e721f6ef2 28 {
hudakz 1:971e721f6ef2 29 xPos = 320;
hudakz 1:971e721f6ef2 30 yPos = 240 / 2;
hudakz 1:971e721f6ef2 31 yPosOld = yPos;
hudakz 1:971e721f6ef2 32 xDir = 0;
hudakz 1:971e721f6ef2 33 yDir = 0;
hudakz 1:971e721f6ef2 34 }
hudakz 1:971e721f6ef2 35
hudakz 1:971e721f6ef2 36 /**
hudakz 1:971e721f6ef2 37 * @brief
hudakz 1:971e721f6ef2 38 * @note
hudakz 1:971e721f6ef2 39 * @param
hudakz 1:971e721f6ef2 40 * @retval
hudakz 1:971e721f6ef2 41 */
hudakz 0:887dd664eca0 42 void Racket::move(DigitalIn* btnUp, DigitalIn* btnDown)
hudakz 0:887dd664eca0 43 {
hudakz 0:887dd664eca0 44 yDir = 0;
hudakz 0:887dd664eca0 45 if (*btnUp == 0)
hudakz 1:971e721f6ef2 46 yDir = -1; // move up
hudakz 0:887dd664eca0 47 if (*btnDown == 0)
hudakz 1:971e721f6ef2 48 yDir = 1; // move down
hudakz 1:971e721f6ef2 49 yPosOld = yPos;
hudakz 0:887dd664eca0 50 yPos += yDir * velocity;
hudakz 0:887dd664eca0 51 if (yPos < height / 2)
hudakz 0:887dd664eca0 52 yPos = height / 2;
hudakz 0:887dd664eca0 53 if (yPos > 240 - height / 2)
hudakz 0:887dd664eca0 54 yPos = 240 - height / 2;
hudakz 0:887dd664eca0 55 }
hudakz 0:887dd664eca0 56
hudakz 0:887dd664eca0 57 /**
hudakz 0:887dd664eca0 58 * @brief
hudakz 0:887dd664eca0 59 * @note
hudakz 0:887dd664eca0 60 * @param
hudakz 0:887dd664eca0 61 * @retval
hudakz 0:887dd664eca0 62 */
hudakz 1:971e721f6ef2 63 void Racket::paint()
hudakz 0:887dd664eca0 64 {
hudakz 1:971e721f6ef2 65 if (yDir == 1) {
hudakz 1:971e721f6ef2 66 tft_boxfill(xPos - width / 2, yPosOld - height / 2, xPos, yPos - height / 2, TFT_BLACK); // hide racket at old position
hudakz 1:971e721f6ef2 67 tft_boxfill(xPos - width / 2, yPos - height / 2, xPos, yPos + height / 2, TFT_WHITE); // draw racket at new position
hudakz 1:971e721f6ef2 68 }
hudakz 1:971e721f6ef2 69 else {
hudakz 1:971e721f6ef2 70 tft_boxfill(xPos - width / 2, yPos + height / 2, xPos, yPosOld + height / 2, TFT_BLACK); // hide racket at old position
hudakz 1:971e721f6ef2 71 tft_boxfill(xPos - width / 2, yPos - height / 2, xPos, yPos + height / 2, TFT_WHITE); // draw racket at new position
hudakz 1:971e721f6ef2 72 }
hudakz 0:887dd664eca0 73 }