

#include
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 LiquidCrystal_I2C lcd(0x27, SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
const int joystickPin = A0;
int joystickValue = 0;
int obstaclePosition = 0;
int playerPosition = 0;
void setup() {
lcd.init();
lcd.backlight();
pinMode(joystickPin, INPUT);
}
void loop() {
joystickValue = analogRead(joystickPin);
if (joystickValue < 400) {
playerPosition -= 1;
} else if (joystickValue > 600) {
playerPosition += 1;
}
obstaclePosition += 1;
if (obstaclePosition >= SCREEN_WIDTH) {
obstaclePosition = 0;
}
lcd.setCursor(0, 0);
lcd.print("Obstacle: ");
lcd.print(obstaclePosition);
lcd.setCursor(0, 1);
lcd.print("Player: ");
lcd.print(playerPosition);
delay(100);
}
No downloadable resources added yet.

Dans ce projet, vous apprendrez à créer un jeu d'évitement d'obstacles simple en utilisant Arduino Uno, un joystick et un écran LCD avec communication I2C. Le jeu mettra au défi le joueur de naviguer à travers des obstacles en contrôlant un personnage avec le joystick.
Veuillez vous connecter pour commenter.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis !