/*
Zweigle D315 mit OLED Anzeige
2024-08-02 noiasca: von 369 auf 120 Zeilen
to be deleted 2024-11-02
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// constants won't change. They're used here to set pin numbers:
constexpr uint8_t Sensor = 2; // Sensor
constexpr uint8_t Reset = 4; // Reset
constexpr uint8_t Rechtslauf = 6; // Rechtslauf
// Variables will change:
int SensorState = 0; // Sensor
int ResetState = 0; // Reset
int RechtslaufState = 0; // Rechtslauf
int lastSensorState = 0;
uint16_t counter[10];
int counterReset = 0; // Zähler Reset
void setup() {
// OLED Display 128x32
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
// initialize as a input:
pinMode(Sensor, INPUT_PULLUP); // Sensor
pinMode(Reset, INPUT_PULLUP); // Reset
pinMode(Rechtslauf, INPUT_PULLUP); // Rechtslauf
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// digitalRead:
SensorState = digitalRead(Sensor); // Sensor
ResetState = digitalRead(Reset); // Reset
RechtslaufState = digitalRead(Rechtslauf); // Rechtslauf
// Reset Zähler 1
if (ResetState == LOW) {
counterReset++;
delay(250);
}
switch (counterReset) {
case 0 :
display.clearDisplay();
display.setTextColor(WHITE); // Textfarbe ()
display.setCursor(5, 0); // erste Zahl von links rein, zweite Zahl von oben rein
display.setTextSize(2); // Textgröße
display.println("Test"); // Text wo auf Bildschirm steht
display.setCursor(5, 16); // erste Zahl von links rein, zweite Zahl von oben rein
display.setTextSize(2); // Textgröße
display.println("D315"); // Text wo auf Bildschirm steht
display.display();
break;
case 1 ... 10 :
// Zähler raufzählen
if (RechtslaufState != LOW && (SensorState != lastSensorState)) {
if (SensorState == LOW) {
counter[counterReset - 1]++;
}
}
// Zähler runterzählen
if (RechtslaufState == LOW && (SensorState != lastSensorState)) {
if (SensorState == LOW) {
counter[counterReset - 1]--;
}
}
display.clearDisplay();
display.setTextColor(WHITE); // Textfarbe ()
display.setCursor(5, 0); // erste Zahl von links rein, zweite Zahl von oben rein
display.setTextSize(2); // Textgröße
display.print("Test "); // Text wo auf Bildschirm steht
display.println(counterReset);
display.setCursor(5, 16); // erste Zahl von links rein, zweite Zahl von oben rein
display.setTextSize(2); // Textgröße
display.println(counter[counterReset - 1]); // Text wo auf Bildschirm steht
display.display();
break;
case 11 :
display.clearDisplay();
display.setTextColor(WHITE); // Textfarbe ()
display.setCursor(5, 10); // erste Zahl von links rein, zweite Zahl von oben rein
display.setTextSize(2); // Textgröße
display.println(F("Data Data")); // Text wo auf Bildschirm steht
display.display();
display.startscrollleft(0x00, 0x0F);
delay(3000);
display.stopscroll();
for (auto & c : counter) {
Serial.print(c);
Serial.print(",");
}
Serial.println();
counterReset++;
break;
case 12 :
counterReset = 0;
for (auto & c : counter) c = 0;
break;
}
}
//