Skip to content

Instantly share code, notes, and snippets.

@brentmc79
Created September 14, 2024 01:20
Show Gist options
  • Save brentmc79/c1e3950df93f692dd90e39dcd49598a1 to your computer and use it in GitHub Desktop.
Save brentmc79/c1e3950df93f692dd90e39dcd49598a1 to your computer and use it in GitHub Desktop.
Lillygo S3 T-Display with Seesaw Gamepad main file
#include "Arduino.h"
#include "Arduino_GFX_Library.h"
#include "Adafruit_seesaw.h"
// Display Config
#define GFX_DEV_DEVICE LILYGO_T_DISPLAY_S3
#define GFX_EXTRA_PRE_INIT() \
{ \
pinMode(15 /* PWD */, OUTPUT); \
digitalWrite(15 /* PWD */, HIGH); \
}
#define GFX_BL 38
Arduino_DataBus *bus = new Arduino_ESP32PAR8Q(
7 /* DC */, 6 /* CS */, 8 /* WR */, 9 /* RD */,
39 /* D0 */, 40 /* D1 */, 41 /* D2 */, 42 /* D3 */,
45 /* D4 */, 46 /* D5 */, 47 /* D6 */, 48 /* D7 */);
Arduino_GFX *gfx = new Arduino_ST7789(
bus, 5 /* RST */, 0 /* rotation */, true /* IPS */,
170 /* width */, 320 /* height */, 35 /* col offset 1 */,
0 /* row offset 1 */, 35 /* col offset 2 */, 0 /* row offset 2 */);
int32_t width, height, center_x, center_y;
// Controller Config
Adafruit_seesaw ss;
#define BUTTON_X 6
#define BUTTON_Y 2
#define BUTTON_A 5
#define BUTTON_B 1
#define BUTTON_SELECT 0
#define BUTTON_START 16
uint32_t button_mask = (1UL << BUTTON_X) | (1UL << BUTTON_Y) | (1UL << BUTTON_START) |
(1UL << BUTTON_A) | (1UL << BUTTON_B) | (1UL << BUTTON_SELECT);
void setup()
{
GFX_EXTRA_PRE_INIT();
#ifdef GFX_BL
pinMode(GFX_BL, OUTPUT);
digitalWrite(GFX_BL, LOW);
analogWrite(GFX_BL, 90);
#endif
Serial.begin(115200);
Serial.println("Hello T-Display-S3");
gfx->begin();
gfx->setRotation(3);
width = gfx->width();
height = gfx->height();
center_x = width / 2;
center_y = height / 2;
Wire.begin();
if(!ss.begin(0x50)){
gfx->fillScreen(BLACK);
gfx->setTextSize(2);
gfx->println("ERROR! seesaw not found");
while(1) delay(1);
}
Serial.println("seesaw started");
ss.pinModeBulk(button_mask, INPUT_PULLUP);
ss.setGPIOInterrupts(button_mask, 1);
}
int last_x = 0, last_y = 0;
void loop(void)
{
gfx->fillScreen(BLACK);
// Draw a circle and make it wobble so the looping is obvious
gfx->fillCircle(center_x+random(20)-10, center_y+random(20)-10, 8, YELLOW);
int x = 1023 - ss.analogRead(14);
int y = 1023 - ss.analogRead(15);
if ( (abs(x - last_x) > 3) || (abs(y - last_y) > 3)) {
Serial.print("x: "); Serial.print(x); Serial.print(", "); Serial.print("y: "); Serial.println(y);
last_x = x;
last_y = y;
}
uint32_t buttons = ss.digitalReadBulk(button_mask);
Serial.println(buttons, BIN);
if (! (buttons & (1UL << BUTTON_A))) {
Serial.println("Button A pressed");
}
if (! (buttons & (1UL << BUTTON_B))) {
Serial.println("Button B pressed");
}
if (! (buttons & (1UL << BUTTON_Y))) {
Serial.println("Button Y pressed");
}
if (! (buttons & (1UL << BUTTON_X))) {
Serial.println("Button X pressed");
}
if (! (buttons & (1UL << BUTTON_SELECT))) {
Serial.println("Button SELECT pressed");
}
if (! (buttons & (1UL << BUTTON_START))) {
Serial.println("Button START pressed");
}
delay(50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment