A simple Pong game with STM32F407VET6 black board (Seeed Arch Max) and ILI9341 320x240 TFT display.
Dependencies: mbed ILI9341_STM32F4
main.cpp
00001 // A simple Pong game with STM32F407VET6 black board (Seeed Arch Max) and ILI9341 320x240 TFT display. 00002 // See more info on the STM32F407VET6 black board at https://os.mbed.com/users/hudakz/code/STM32F407VET6_Hello/ 00003 // 00004 #include "mbed.h" 00005 #include "tft.h" 00006 #include "Racket.h" 00007 #include "Ball.h" 00008 00009 // Connect the SPI interface of an ILI9341 320x240 TFT display to the STM32F407VET6 board (Seeed Arch Max) as follows: 00010 00011 // ILI9341 STM32F407VET6 00012 // VCC +5V 00013 // GND GND 00014 // CS PB_7 00015 // RESET PB_8 00016 // D/C PB_6 00017 // SDI(MOSI) PB_5 00018 // SCK PB_3 00019 // LED over a 56 ohm resistor +5V 00020 // SDO(MISO) PB_4 00021 // 00022 Ticker ticker; 00023 DigitalIn racketUp(PE_4, PullUp); // K0 button 00024 DigitalIn racketDown(PE_3, PullUp); // K1 button 00025 Ball ball; 00026 Racket racket; 00027 volatile bool gameOn; 00028 volatile bool missed; 00029 Timeout timeout; 00030 00031 /** 00032 * @brief 00033 * @note 00034 * @param 00035 * @retval 00036 */ 00037 void newGame() 00038 { 00039 tft_clear(TFT_BLACK); 00040 racket.home(); 00041 ball.home(); 00042 gameOn = true; 00043 } 00044 00045 /** 00046 * @brief 00047 * @note 00048 * @param 00049 * @retval 00050 */ 00051 void gameOver() 00052 { 00053 gameOn = false; 00054 tft_text(320 / 2 - 35, 240 / 2, "GAME OVER", TFT_WHITE, TFT_BLACK); 00055 timeout.attach(callback(newGame), 2); 00056 } 00057 00058 /** 00059 * @brief 00060 * @note 00061 * @param 00062 * @retval 00063 */ 00064 void updateField() 00065 { 00066 if (gameOn) { 00067 racket.move(&racketUp, &racketDown); // move racket 00068 racket.paint(); // paint racket 00069 missed = ball.move(&racket); // move ball and check for collisions 00070 if (missed) 00071 gameOver(); 00072 else 00073 ball.paint(); // paint ball 00074 } 00075 } 00076 00077 /** 00078 * @brief 00079 * @note 00080 * @param 00081 * @retval 00082 */ 00083 int main() 00084 { 00085 tft_init(); 00086 newGame(); 00087 ticker.attach_us(updateField, 20 * 1000); // update period = 20 ms 00088 while (true) { } 00089 }
Generated on Mon Jul 25 2022 11:48:50 by 1.7.2