#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] =
{ 0b00000000, 0b11000000,
0b00000001, 0b11000000,
0b00000001, 0b11000000,
0b00000011, 0b11100000,
0b11110011, 0b11100000,
0b11111110, 0b11111000,
0b01111110, 0b11111111,
0b00110011, 0b10011111,
0b00011111, 0b11111100,
0b00001101, 0b01110000,
0b00011011, 0b10100000,
0b00111111, 0b11100000,
0b00111111, 0b11110000,
0b01111100, 0b11110000,
0b01110000, 0b01110000,
0b00000000, 0b00110000 };
//Taster Ports
uint8_t esc = 4;
uint8_t left = 8;
uint8_t up = 7;
uint8_t right = 6;
uint8_t down = 5;
//Taster Status
boolean escStatus;
boolean leftStatus;
boolean upStatus;
boolean rightStatus;
boolean downStatus;
//Buzzer Pin
uint8_t buzzerPin = 2;
//RGB LED Pins
uint8_t rLed = 11;
uint8_t gLed = 10;
uint8_t bLed = 9;
//Funktionen dekleration
void updateButton();
void setup() {
Serial.begin(9600);
//PinMode Taster
pinMode(esc, INPUT);
pinMode(left, INPUT);
pinMode(up, INPUT);
pinMode(right, INPUT);
pinMode(down, INPUT);
//PinMode LED
pinMode(rLed, OUTPUT);
pinMode(gLed, OUTPUT);
pinMode(bLed, OUTPUT);
//Oled Display initialisierung und Test
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
display.setRotation(3);
// Draw a single pixel in white
display.drawRect(10, 10, 44, 108, SSD1306_WHITE);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(2000);
// display.display() is NOT necessary after every single drawing command,
// unless that's what you want...rather, you can batch up a bunch of
// drawing operations and then update the screen all at once by calling
// display.display(). These examples demonstrate both approaches...
// Invert and restore display, pausing in-between
display.invertDisplay(true);
delay(1000);
display.invertDisplay(false);
delay(1000);
display.clearDisplay();
display.display();
//Taster Test
updateButton();
delay(100);
if(escStatus||leftStatus||upStatus||rightStatus||downStatus) {
Serial.println("Not all Buttons are released, please do not press any button to continue!");
while(escStatus||leftStatus||upStatus||rightStatus||downStatus) {
updateButton();
}
}
//Buzzer Test
tone(buzzerPin, 350);
delay(50);
noTone(buzzerPin);
//Led Test
digitalWrite(rLed, 255);
digitalWrite(gLed, 0);
digitalWrite(bLed, 0);
delay(200);
digitalWrite(rLed, 0);
digitalWrite(gLed, 255);
digitalWrite(bLed, 0);
delay(200);
digitalWrite(rLed, 0);
digitalWrite(gLed, 0);
digitalWrite(bLed, 255);
delay(200);
digitalWrite(rLed, 0);
digitalWrite(gLed, 0);
digitalWrite(bLed, 0);
Serial.println("Setup done!");
}
void loop() {
}
void updateButton() {
escStatus = digitalRead(esc);
leftStatus = digitalRead(left);
upStatus = digitalRead(up);
rightStatus = digitalRead(right);
downStatus = digitalRead(down);
}