#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "sketch.h"
#include "Player.cpp"
#include "Joystick.cpp"
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
int SCREEN_WIDTH = 128;
int SCREEN_HEIGHT = 64;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Player player(SCREEN_WIDTH /2,0);
Joystick js(15,2,18);
void setup() {
js.setup();
Serial.begin(115200);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
}
int heading = 3;
void loop() {
if(js.get() > 0) {
heading = js.get();
}
switch(heading) {
case 1:
player.up();
break;
case 2:
player.right();
break;
case 3:
player.down();
break;
case 4:
player.left();
break;
}
Serial.println(js.read().x());
Serial.println(js.read().y());
player.show();
delay(10);
}