#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#define OLED_WIDTH 128
#define OLED_HEIGHT 64
#define OLED_ADDR 0x3C
Adafruit_SSD1306 oled(OLED_WIDTH, OLED_HEIGHT);
const int onoff_sw = 16;  // On/Off switch
const int pump_sw = 17;   // Pump allowance
const int onoff_sw_led = 18;  // On/Off switch
const int pump_sw_led = 19;   // Pump allowance
int onoffState = LOW;  // variable for reading the pushbutton status
int pumpState = LOW;   // variable for reading the pushbutton status
void setup() {
  // put your setup code here, to run once:
  Wire.setSDA(0);
  Wire.setSCL(1);
  Wire.begin();
  Wire.setClock(10000);
  oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  oled.clearDisplay();
  oled.display();
  pinMode(onoff_sw_led, OUTPUT);
  pinMode(pump_sw_led, OUTPUT);
  pinMode(onoff_sw, INPUT_PULLUP);
  pinMode(pump_sw, INPUT_PULLUP);
  onoffState = digitalRead(onoff_sw);
  pumpState = digitalRead(pump_sw);
  attachInterrupt(digitalPinToInterrupt(onoff_sw), alarm, CHANGE);
  attachInterrupt(digitalPinToInterrupt(pump_sw), alarm, CHANGE);
  oleddisp();
}
void loop() {
  // put your main code here, to run repeatedly:
}
void alarm() {
  onoffState = digitalRead(onoff_sw);
  pumpState = digitalRead(pump_sw);
 
  oleddisp();
  ledout();
}
void ledout() {
   if (onoffState = HIGH)
    digitalWrite(onoff_sw_led, HIGH);
  else digitalWrite(onoff_sw_led, LOW);
  if (pumpState = HIGH)
    digitalWrite(pump_sw_led, HIGH);
  else digitalWrite(pump_sw_led, LOW);
}
void oleddisp() {
  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setTextColor(WHITE);
  oled.setCursor(0, 17);
  oled.print("Power SW: ");
  oled.println(!onoffState);
  oled.print("Pump SW: ");
  oled.println(!pumpState);
  oled.display();
}