// int x_pin = A0;
// int y_pin = A1;
// int sw_pin = 3;
// //digitalWrite(2,HIGH); //it generates the o/p as 1 while we press it displays 0
// void setup()
// {
// Serial.begin(9600);
// pinMode(A0, INPUT);
// pinMode(A1, INPUT);
// pinMode(3, INPUT);
// }
// void loop()
// {
// int x_data = analogRead(A0);
// int y_data = analogRead(A1);
// int sw_data = digitalRead(3);
// Serial.print("x_data: ");
// Serial.print(x_data);
// Serial.print("\t");
// Serial.print("y_data: ");
// Serial.print(y_data);
// Serial.print("\t");
// Serial.print("sw_data: ");
// Serial.println(sw_data);
// digitalWrite(3,HIGH);
// delay(500);
// }
// #include <Wire.h>
// #include <LiquidCrystal_I2C.h>
// // Set the LCD address to 0x27 for a 16 chars and 2 line display
// LiquidCrystal_I2C lcd(0x27, 16, 2);
// void setup()
// {
// // initialize the LCD
// lcd.begin();
// // Turn on the blacklight and print a message.
// lcd.backlight();
// //lcd.print("Hello, world!");
// }
// void loop()
// {
// // Do nothing here...
// lcd.clear();
// lcd.print("Hello World!");
// delay(1000);
// lcd.clear();
// lcd.print("I'm powered by");
// lcd.setCursor(3,1);
// lcd.print("Arduino!");
// delay(1000);
// lcd.clear();
// lcd.print("Please subscribe!");
// delay(1000);
// lcd.clear();
// lcd.print("Goodbye!");
// delay(1000);
// lcd.clear();
// }
// #include <Wire.h>
// #include <LiquidCrystal_I2C.h>
// LiquidCrystal_I2C lcd(0x27, 16, 2);
// int x_pin = A0;
// int y_pin = A1;
// int sw_pin = 3;
// void setup()
// {
// Serial.begin(9600);
// pinMode(A0, INPUT);
// pinMode(A1, INPUT);
// pinMode(3, INPUT);
// lcd.begin(16,2);
// lcd.backlight();
// }
// void loop()
// {
// int x_data = analogRead(A0);
// int y_data = analogRead(A1);
// int sw_data = digitalRead(3);
// Serial.print("x_data: ");
// Serial.print(x_data);
// Serial.print("\t");
// Serial.print("y_data: ");
// Serial.print(y_data);
// Serial.print("\t");
// Serial.print("sw_data: ");
// Serial.println(sw_data);
// digitalWrite(3,HIGH);
// lcd.clear();
// lcd.print("x = ");
// lcd.print(x_data);
// lcd.setCursor(9, 0);
// lcd.print("y = ");
// lcd.print(y_data);
// lcd.setCursor(0,1);
// lcd.print("sw = ");
// lcd.print(sw_data);
// delay(100);
// }
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define JOYSTICK_I2C_ADDRESS 0x3C // Replace ?? with the actual I2C address of your joystick
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
// Initialize the display with the I2C address 0x3C
// if(!display.begin(SSD1306_I2C_ADDRESS, 0, 0)) {
// Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display(); // Clear the display buffer
delay(2000); // Pause for 2 seconds
display.clearDisplay(); // Clear the display buffer
display.setTextSize(1); // Set text size to 1
display.setTextColor(SSD1306_WHITE); // Set text color to white
display.setCursor(0, 0);
display.println("Joystick Data:");
display.display(); // Show the display buffer
Wire.begin();
}
void loop() {
// Request 6 bytes of data from the joystick
// Wire.requestFrom(JOYSTICK_I2C_ADDRESS, 6);
// Read the data from the joystick
while (Wire.available()) {
int x = Wire.read() << 8 | Wire.read(); // Combine two bytes into an integer
int y = Wire.read() << 8 | Wire.read();
int buttonState = Wire.read();
// Print the values to the Serial Monitor
Serial.print("X: ");
Serial.print(x);
Serial.print("\tY: ");
Serial.print(y);
Serial.print("\tButton: ");
Serial.println(buttonState);
// Display data on OLED
display.clearDisplay();
display.setCursor(0, 10);
display.print("X: ");
display.println(x);
display.setCursor(0, 30);
display.print("Y: ");
display.println(y);
display.setCursor(0, 50);
display.print("Button: ");
display.println(buttonState);
display.display();
}
delay(100); // Adjust the delay as needed
}