2023/12/28
// 測試 Pico_Game 上的八個按鈕及螢幕顯示
// 此範例使用 TFT_eSPI library 來顯示 ILI9341 螢幕
// 2023/10/4 by Mason
#include <TFT_eSPI.h>
#include <SPI.h>
#include <Arduino.h>
#include "picogame_base_yellow.c" // 匯入自己的照片檔
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
const int BTN_A = 2;
const int BTN_B = 14;
const int BTN_up = 8;
const int BTN_down = 7;
const int BTN_left = 15;
const int BTN_right = 9;
const int BTN_menu = 1;
const int BTN_start = 0;
String label ="";
void setup()
{
Serial.begin(9600);
pinMode(BTN_A, INPUT_PULLUP);
pinMode(BTN_B, INPUT_PULLUP);
pinMode(BTN_up, INPUT_PULLUP);
pinMode(BTN_down, INPUT_PULLUP);
pinMode(BTN_left, INPUT_PULLUP);
pinMode(BTN_right, INPUT_PULLUP);
pinMode(BTN_menu, INPUT_PULLUP);
pinMode(BTN_start, INPUT_PULLUP);
tft.init();
tft.invertDisplay(true);
tft.setRotation(1);
tft.setSwapBytes(true);
tft.fillScreen(TFT_BLACK); // 清空螢幕
tft.setSwapBytes(true); // 設定颜色由RGB->BGR
tft.pushImage(3, 50, 314, 144, picogame_base_yellow); // 換成您要顯示的照片
}
void loop() {
if (digitalRead(BTN_A) == LOW) { // 按鈕 A 按下
label=" A";
} else if (digitalRead(BTN_B) == LOW) { // 按鈕 B 按下
label=" B";
} else if (digitalRead(BTN_up) == LOW) { // 按鈕 UP 按下
label="Up";
} else if (digitalRead(BTN_down) == LOW) { // 按鈕 Down 按下
label="Down";
} else if (digitalRead(BTN_left) == LOW) { // 按鈕 Left 按下
label="Left";
} else if (digitalRead(BTN_right) == LOW) { // 按鈕 Right 按下
label="Right";
} else if (digitalRead(BTN_menu) == LOW) { // 按鈕 Menu 按下
label="Menu";
} else if (digitalRead(BTN_start) == LOW) { // 按鈕 Start 按下
label="START";
} else {
label =" ";
}
tft.drawString(label,150,108,2);
}