#define VERT_PIN A0
#define HORZ_PIN A1
#define SEL_PIN 2
#include "ssd1306.h"
// Bitmap for image
const uint8_t Soba [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80,
0x09, 0x00, 0x00, 0x00, 0xc0, 0x0c, 0x00, 0x00,
0x00, 0x60, 0x06, 0x00, 0x00, 0x00, 0x30, 0x03,
0x00, 0x00, 0x00, 0x98, 0x01, 0x00, 0xf8, 0x00,
0xcc, 0x00, 0x00, 0xde, 0x03, 0x66, 0x00, 0x80,
0x07, 0x0f, 0x33, 0x00, 0xc0, 0x01, 0x9c, 0x19,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
0xff, 0xff, 0x07, 0xe0, 0xff, 0xff, 0xff, 0x07,
0xe0, 0xff, 0xff, 0xff, 0x07, 0xe0, 0xff, 0xff,
0xff, 0x07, 0xe0, 0xff, 0xff, 0xff, 0x07, 0xc0,
0xff, 0xff, 0xff, 0x03, 0xc0, 0xff, 0xff, 0xff,
0x03, 0x80, 0xff, 0xff, 0xff, 0x01, 0x80, 0xff,
0xff, 0xff, 0x01, 0x00, 0xff, 0xff, 0xff, 0x00,
0x00, 0xfe, 0xff, 0x7f, 0x00, 0x00, 0xfc, 0xff,
0x3f, 0x00, 0x00, 0xf8, 0xff, 0x1f, 0x00, 0x00,
0xf0, 0xff, 0x0f, 0x00, 0x00, 0xc0, 0xff, 0x03,
0x00, 0x00, 0x80, 0xff, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() {
ssd1306_128x64_i2c_init();
ssd1306_clearScreen( );
ssd1306_drawXBitmap(0, 0, 60, 32, Soba);
pinMode(VERT_PIN, INPUT);
pinMode(HORZ_PIN, INPUT);
pinMode(SEL_PIN, INPUT_PULLUP);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
}
void loop() {
// Declaring Variables
int vert = analogRead(VERT_PIN);
int horz = analogRead(HORZ_PIN);
bool selPressed = digitalRead(SEL_PIN) == LOW;
digitalWrite(3, HIGH);
// Draws the bitmap onto the connected screen
// horz goes from 0 (right) to 1023 (left)
// vert goes from 0 (bottom) to 1023 (top)
// selPressed is true is the joystick is pressed
// If the joystick is moved up or down, the corresponding pins are set to HIGH. Otherwise the pins are set to LOW.
if (vert >= 1023) {
digitalWrite(13, HIGH);
} else if (vert <= 0) {
digitalWrite(12, HIGH);
} else {
digitalWrite(13, LOW);
digitalWrite(12, LOW);
}
// If the joystick is moved left or right, the corresponding pins are set to HIGH. Otherwise the pins are set to LOW.
if (horz >= 1023) {
digitalWrite(8, HIGH);
} else if (horz <= 0) {
digitalWrite(4, HIGH);
} else {
digitalWrite(8, LOW);
digitalWrite(4, LOW);
}
// If the center button on the joystick is pressed, the corresponding pin is set to HIGH. Otherwise the pins are set to LOW
if (selPressed == true) {
digitalWrite(7, HIGH);
} else {
digitalWrite(7, LOW);
}
}