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
Revision:
0:887dd664eca0
Child:
1:971e721f6ef2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Apr 11 20:18:15 2019 +0000
@@ -0,0 +1,58 @@
+// A simple Pong game with the STM32F407VET6 black board (Seeed Arch Max) and ILI9341 320x240 TFT display.
+// More info on STM32F407VET6 black board at https://os.mbed.com/users/hudakz/code/STM32F407VET6_Hello/
+//
+#include "mbed.h"
+#include "tft.h"
+#include "Racket.h"
+#include "Ball.h"
+
+// Connect the SPI interface of an ILI9341 320x240 TFT display to the STM32F407VET6 board (Seeed Arch Max) as follows:
+// ILI9341                      STM32F103C8T6
+//   VCC                            +5V
+//   GND                            GND
+//   CS                             PB_7
+//   RESET                          PB_8
+//   D/C                            PB_6
+//   SDI(MOSI)                      PB_5
+//   SCK                            PB_3
+//   LED   over a 56 ohm resistor   +5V
+//   SDO(MISO)                      PB_4
+//
+Ticker      ticker;
+DigitalIn   racketUp(PE_4, PullUp);     // K0 button
+DigitalIn   racketDown(PE_3, PullUp);   // K1 button
+Ball        ball;
+Racket      racket;
+bool        gameOver;
+
+/**
+ * @brief
+ * @note
+ * @param
+ * @retval
+ */
+void updateField()
+{
+    racket.paint(TFT_BLACK);                // hide racket at old position
+    racket.move(&racketUp, &racketDown);    // move racket
+    racket.paint(TFT_WHITE);                // draw racket at new position
+    if (!gameOver)
+        ball.paint(TFT_BLACK);              // hide ball at old position
+    gameOver = ball.move(&racket);          // move ball and check for collisions + game over
+    if (!gameOver)
+        ball.paint(TFT_WHITE);              // draw ball at new position
+}
+
+/**
+ * @brief
+ * @note
+ * @param
+ * @retval
+ */
+int main()
+{
+    tft_init();
+    tft_clear(TFT_BLACK);
+    ticker.attach_us(updateField, 40 * 1000);   // update period = 40 ms
+    while (true) { }
+}