#include <LedControl.h>
int DIN = 11;
int CS = 10;
int CLK = 13;
#define VERT_PIN A0
#define HORZ_PIN A1
#define SEL_PIN 2
LedControl lc=LedControl(DIN, CLK, CS,0);
void setup() {
// put your setup code here, to run once:
lc.shutdown(0,false);
lc.setIntensity(0,0);
lc.clearDisplay(0);
pinMode(VERT_PIN, INPUT);
pinMode(HORZ_PIN, INPUT);
pinMode(SEL_PIN, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
int vert = analogRead(VERT_PIN);
int horz = analogRead(HORZ_PIN);
bool selPressed = digitalRead(SEL_PIN) == LOW;
}
/*#include <LedControl.h>
// MAX7219 pins: DIN, CLK, CS
LedControl lc = LedControl(12, 11, 10, 1);
// Joystick
const int joyYPin = A0;
// Game variables
int birdY = 3;
int obstacleX = 7;
int gapY = 3;
unsigned long lastMove = 0;
unsigned long gameSpeed = 200;
bool gameOver = false;
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
randomSeed(analogRead(1));
}
void loop() {
if (gameOver) {
showGameOver();
delay(2000);
resetGame();
return;
}
readJoystick();
applyGravity();
if (millis() - lastMove > gameSpeed) {
moveObstacle();
lastMove = millis();
}
checkCollision();
drawGame();
}
void readJoystick() {
int joyY = analogRead(joyYPin);
if (joyY < 400 && birdY > 0) {
birdY--;
}
}
void applyGravity() {
static unsigned long gravityTimer = 0;
if (millis() - gravityTimer > 300) {
if (birdY < 7) birdY++;
gravityTimer = millis();
}
}
void moveObstacle() {
obstacleX--;
if (obstacleX < 0) {
obstacleX = 7;
gapY = random(1, 6);
}
}
void checkCollision() {
if (obstacleX == 1) {
if (birdY != gapY && birdY != gapY + 1) {
gameOver = true;
}
}
}
void drawGame() {
lc.clearDisplay(0);
// Draw bird
lc.setLed(0, birdY, 1, true);
// Draw obstacle
for (int y = 0; y < 8; y++) {
if (y != gapY && y != gapY + 1) {
lc.setLed(0, y, obstacleX, true);
}
}
}
void showGameOver() {
lc.clearDisplay(0);
for (int i = 0; i < 8; i++) {
lc.setLed(0, i, i, true);
lc.setLed(0, i, 7 - i, true);
}
}
void resetGame() {
birdY = 3;
obstacleX = 7;
gapY = random(1, 6);
gameOver = false;
lc.clearDisplay(0);
}
*/