// NOTE : This isn't Friday Night Funkin'. Do you even know it, btw?
// Check out my other creations!
// Normal Piano : https://wokwi.com/projects/419854398188207105
// Mini Piano : https://wokwi.com/projects/421112780411951105
// Keypad and Oled : https://wokwi.com/projects/421300031153052673
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// Pin definitions for the ILI9341 and touch screen
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
// Define screen dimensions
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320
// Create instances for the TFT
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
const int joyXPin = A1; // HORZ (X-axis)
const int joyYPin = A0; // VERT (Y-axis)
const int buttonPin = 2; // SEL (Button)
const int buzzerPin = 3; // Buzzer
// Variables to store previous joystick values and button state
int prevJoyX = -1;
int prevJoyY = -1;
int prevButtonState = HIGH;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP); // Set the joystick button pin as input with internal pull-up resistor
pinMode(buzzerPin, OUTPUT); // Set the buzzer pin as output
tft.begin();
tft.setRotation(3); // Adjust rotation as needed
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(10, 10);
tft.print("Loading setup...");
delay(3000);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 10);
tft.print("Setup done");
delay(2000);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 10);
tft.print("Game info will be shown");
tft.setCursor(10, 30);
tft.print("Please wait...");
delay(2000);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 10);
tft.print("Game : Joystick Clicker");
delay(2000);
tft.setCursor(10, 30);
tft.print("Game ID : 00000001# (1/1)");
delay(3000);
tft.setCursor(10, 60);
tft.print("Creator : Tugus/Terckto");
delay(1000); // Display setup message for 1 second
tft.fillScreen(ILI9341_BLACK); // Clear the screen after the setup message
}
void loop() {
int joyX = analogRead(joyXPin); // Read X-axis value
int joyY = analogRead(joyYPin); // Read Y-axis value
int buttonState = digitalRead(buttonPin); // Read joystick button state
// Play sound for X-axis or Y-axis
if (joyX != prevJoyX) {
tone(buzzerPin, 1000, 100); // Play tone at 1000 Hz for X-axis
}
if (joyY != prevJoyY) {
tone(buzzerPin, 1500, 100); // Play tone at 1500 Hz for Y-axis
}
if (buttonState == LOW && prevButtonState != LOW) {
tone(buzzerPin, 2000, 100); // Play tone at 2000 Hz for button press
}
// Update display if values have changed
if (joyX != prevJoyX || joyY != prevJoyY || buttonState != prevButtonState) {
// Clear only the part of the screen that needs updating
tft.fillRect(10, 10, SCREEN_WIDTH - 20, SCREEN_HEIGHT - 20, ILI9341_BLACK);
// Display joystick values
tft.setCursor(10, 10);
tft.print("Joystick X: ");
tft.print(joyX);
tft.setCursor(10, 30);
tft.print("Joystick Y: ");
tft.print(joyY);
// Display button state
tft.setCursor(10, 50);
tft.print("Button: ");
if (buttonState == LOW) {
tft.print("Pressed");
} else {
tft.print("Not Pressed");
}
// Update previous values
prevJoyX = joyX;
prevJoyY = joyY;
prevButtonState = buttonState;
}
delay(100); // Small delay for better readability
}
/*
tft.begin();
tft.setRotation(3); // Adjust rotation as needed
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(10, 10);
tft.print("Loading setup...");
delay(3000);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 10);
tft.print("Setup done");
delay(2000);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 10);
tft.print("Game info will be shown");
tft.setCursor(10, 30);
tft.print("Please wait...");
delay(2000);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 10);
tft.print("Game : DefaultGame#1");
delay(2000);
tft.setCursor(10, 30);
tft.print("Game ID : 00000001# (1/1)");
delay(3000);
tft.setCursor(10, 60);
tft.print("Creator : Tugus/Terckto");
*/