#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <OneButton.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_SH1107 display = Adafruit_SH1107(64, 128, &Wire);
int x = 0;
int blink = LOW;
int waterValue = 0;
//KNOP DECLARATIES
OneButton PLUS(0, true, true);
OneButton MIN(13, true, true);
OneButton ENTER(12, true, true);
OneButton RESET(14, true, true);
void setup() {
Serial.begin(9600);
//INPUT DECLARATIE VOOR KNOPPEN
PLUS.attachClick(Plus);
MIN.attachClick(Min);
ENTER.attachClick(EnterShort);
ENTER.attachLongPressStart(EnterLong);
RESET.attachClick(Reset);
display.begin(0x3C, true); // Address 0x3C default
display.clearDisplay(); // wis het display
display.setTextSize(3); // Draw 2X-scale text
display.setTextColor(SH110X_WHITE);
display.setCursor(0, 0);
display.println("Medi");
display.display();
}
void loop() {
PLUS.tick();
MIN.tick();
ENTER.tick();
RESET.tick();
delay(10);
if (blink == HIGH) {
x++;
if (x == 50) {
display.clearDisplay();
display.setTextSize(3); // Draw 2X-scale text
display.setTextColor(SH110X_WHITE);
display.setCursor(10, 0);
display.println(waterValue);
display.display(); // Show initial text
}
if (x == 100) {
display.clearDisplay();
display.display();
x = 0;
}
}
}
void Plus() {
if (blink == HIGH) {
waterValue = waterValue + 50;
x = 47;
}
}
void Min() {
if (blink == HIGH) {
if (waterValue >= 50) {
waterValue = waterValue - 50;
x = 47;
}
else {
waterValue = 0;
x = 47;
}
}
}
void EnterShort() {
if (blink == HIGH) {
blink = LOW;
}
display.clearDisplay();
display.setTextSize(3); // Draw 2X-scale text
display.setTextColor(SH110X_WHITE);
display.setCursor(10, 0);
display.println(waterValue);
display.display(); // Show initial text
delay(2000);
display.clearDisplay();
display.display();
}
void EnterLong() { //lang drukken op enter om water value aan te passen
x = 47;
blink = HIGH;
}
void Reset() {
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(SH110X_WHITE);
display.setCursor(10, 0);
display.println("RESET");
display.display(); // Show initial text
delay(1000);
display.clearDisplay();
display.display();
waterValue = 0;
display.setCursor(10, 0);
display.println(waterValue);
display.println("ml");
display.display(); // Show initial text
delay(1000);
display.clearDisplay();
display.display();
}