#include <Wire.h>
#include "SH1106Wire.h" // legacy: #include "SH1106.h"
#include <Bounce2.h>
#include <Dialog_bold_14.h> //
SH1106Wire lcd(0x3c, SDA, SCL); // ADDRESS, SDA, SCL
#define BUTTON_PIN_1 12
#define BUTTON_PIN_2 13
const byte flashPin = 35;
const byte LEDPin = 2; //interne LED
const byte LED_PIN1 = 18; //externe LED
const byte LED_PIN2 = 19; //externe LED
volatile bool ledState = LOW;
unsigned int val = 25;
bool value1 = LOW;
bool value2 = LOW;
//------------------------------
const int pwmPin = 18; // = GPIO18
const int freq = 2000;
const int pwmChannel = 0; // choose 0 - 15
const int res = 8; // 2^8 = 256
//---------------------------
// Instantiate a Bounce object
Bounce debouncer1 = Bounce();
Bounce debouncer2 = Bounce();
unsigned int c1;
bool bSt1 = 0;
bool bSt2 = 0;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
Serial.begin(115200);
pinMode(LEDPin, OUTPUT);
pinMode(LED_PIN1,OUTPUT);
pinMode(LED_PIN2,OUTPUT);
pinMode(flashPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(flashPin), func_Flash, FALLING);
// Setup the first button with an internal pull-up :
pinMode(BUTTON_PIN_1,INPUT_PULLUP);
// After setting up the button, setup the Bounce instance :
debouncer1.attach(BUTTON_PIN_1);
debouncer1.interval(20); // interval in ms
// Setup the second button with an internal pull-up :
pinMode(BUTTON_PIN_2,INPUT_PULLUP);
// After setting up the button, setup the Bounce instance :
debouncer2.attach(BUTTON_PIN_2);
debouncer2.interval(20); // interval in ms
ledcAttach(pwmPin, freq, res); // channel is chosen automatically
lcd.init();
lcd.flipScreenVertically();
lcd.setContrast(255);
lcd.clear();
startScreen();
}
// the loop function runs over and over again forever
void loop() {
button();
lcd.clear();
//lcd.drawString(5, 30,String(value1));
//lcd.drawString(25,30,String(value2));
//lcd.display();//write buffer
// Serial.println("Kein Interrupt");
// delay(100);
ledcWrite(pwmPin, (c1*12));//240
//Serial.println((c1*12));
//drawProgressBarDemo();
//digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
if ( ledState == HIGH){
delay(100); // wait for a second
digitalWrite(LEDPin, LOW); // turn the LED off by making the voltage LOW
//delay(1000); // wait for a second
ledState = LOW;
}
// delay(1000); // wait for a second
// digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
// delay(1000); // wait for a second
}
ICACHE_RAM_ATTR void func_Flash() {
//IRAM_ATTR void func_Flash() {
digitalWrite(LEDPin, HIGH); // turn the LED on (HIGH is the voltage level)
ledState = HIGH;
//Serial.println("brightness: " + String(brightness));
}
//--------------------------------------------------------