#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Encoder.h>
/*
+++++++++++++++++++++++++++++++++++++++
Display (OLED 128x64)
fontsize 6x8 (default)
+++++++++++++++++++++++++++++++++++++++
*/
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// declare an SSD1306 display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
/*
+++++++++++++++++++++++++++++++++++++++
Encoder
+++++++++++++++++++++++++++++++++++++++
*/
Encoder myEnc(18, 19);
// avoid using pins with LEDs attached
long oldPosition = -999;
int writeInLine = 2;
/*
+++++++++++++++++++++++++++++++++++++++
Setup
+++++++++++++++++++++++++++++++++++++++
*/
void setup() {
Serial.begin(9600); // Serial display
// initialize OLED display with address 0x3C for 128x64
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
while (true);
}
delay(2000); // wait for initializing
startDisplay();
}
/*
+++++++++++++++++++++++++++++++++++++++
Loop
+++++++++++++++++++++++++++++++++++++++
*/
void loop() {
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
Serial.println(newPosition);
oled.setCursor(0,9);
oled.writeFillRect(0,9,25,8,BLACK);
oled.print(newPosition);
oled.display();
}
}
/*
+++++++++++++++++++++++++++++++++++++++
Funktionen
+++++++++++++++++++++++++++++++++++++++
*/
void startDisplay(){
oled.clearDisplay(); // clear display
oled.setTextSize(1); // text size, minimum 1
oled.setTextColor(WHITE); // text color
oled.setRotation(3); // rotate text (270°)
oled.setCursor(0, 0); // position to display
oled.println("Staerke: "); // text to display
oled.setCursor(27,9); //line 2
oled.println("mW/cm2");
oled.println("Zeit: ");
oled.setCursor(27,27); //line 4
oled.println("ms");
oled.println("Shutter- position: ");
oled.println("l[ ], r[ ]");
oled.println("m[ ], n[ ]");
oled.drawLine(0,70,64,70,WHITE);
oled.setCursor(0,73);
oled.println("Abstand: ");
oled.setCursor(27,82);
oled.println("cm");
oled.println("Dosis: ");
oled.setCursor(27,100); //line 6
oled.println("J");
oled.display(); // show on OLED
}
void setValue(int writeInLine){
}