hi @zhomeslice
here is my code and yours integrated
#include <Arduino.h>
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
//#include<DHTesp.h>
#include <Wire.h>
#include <Firebase_ESP_Client.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_AHTX0.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
//Provide the token generation process info.
#include "addons/TokenHelper.h"
//Provide the RTDB payload printing info and other helper functions.
#include "addons/RTDBHelper.h"
// Insert your network credentials
#define WIFI_SSID "xxx"
#define WIFI_PASSWORD "1234567a"
// Insert Firebase project API Key
#define API_KEY "AIzaSyDxRT8-0O8lIZnt9aWazSgo"
// Insert RTDB URLefine the RTDB URL */
#define DATABASE_URL "https://essu-default-rtdb.firebaseio.com/"
//Define Firebase Data object
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
uint32_t Time_aht;
uint32_t Time_lim;
uint32_t Time_oled;
uint32_t Time_fb;
Adafruit_AHTX0 aht;
#define bCLK 2
#define bDT 0
#define bSW 5
int prevClk1 = HIGH;
//portMUX_TYPE gpioMux = portMUX_INITIALIZER_UNLOCKED;
bool signupOK = false;
String stringValue;
String stringVal;
float temperature;
float humidity;
int lim=10; // limit of temperature
int count = 10;
int oldval=10;
int newfb;
void drawUpdateOLED(float temp, float humi, int st) {
delay(2000);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(5, 5);
display.println("Temp:");
display.setCursor(65, 5);
display.print(temp,1);
display.setCursor(5, 20);
display.println("Hum.:");
display.setCursor(65, 20);
display.print(humi,1);
display.setCursor(5, 35);
display.println("lim.:");
display.setCursor(65, 35);
display.print(st);
display.drawRoundRect(10, 58, 102, 1, 1, WHITE);
display.setCursor((st-10)*5,45) ;
display.println(".");
// display.fillRect(10, 56, (st-10)*5, 5, WHITE);
display.display();
}
uint32_t getStartTime(uint32_t DataCaptureDelay) {
return millis() + DataCaptureDelay;
}
///////////////////////// InitializeAHT
void initAHT(){
if (! aht.begin()) {
Serial.println("Could not find AHT? Check wiring");
while (1) delay(10);
}
Serial.println("AHT10 or AHT20 found");
}
//////////////////////// Initialize WiFi
void initWiFi() {
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to WF ..");
delay(1000);
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.println(WiFi.localIP());
Serial.println();
/* Assign the api key (required) */
config.api_key = API_KEY;
/* Assign the RTDB URL (required) */
config.database_url = DATABASE_URL;
/* Sign up */
if (Firebase.signUp(&config, &auth, "", "")){
Serial.println("ok");
signupOK = true;
}
else{
Serial.printf("%s\n", config.signer.signupError.message.c_str());
}
/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
}
///////////////////////////Rotary encoder
ICACHE_RAM_ATTR void isrAB() {
(digitalRead(bDT)) ? lim++ : lim--;
if (lim > 30)lim = 30;
if (lim < 10)lim = 10;
}
//Serial.println(lim);
//haschanged(lim);
//}
/////////////////////////////check if last value has changed
//void haschanged(int newval){
// if(newval==oldval){
// lim=oldval;
// }else{
// lim=newval;
// oldval=newval;
// count=newval;
//
// }
//fbsetlim();
// Serial.println("lim");
// Serial.println(lim);
// }
/////////////////////////////if last value has changed send firebase
//void fbsetlim(){
// if (Firebase.ready() && signupOK){
//Firebase.RTDB.setInt(&fbdo, "test/lim", lim);
//Serial.println("lim");
// Serial.println(lim);
// delay(500);
// }
//}
void setup() {
Serial.begin(115200);
// Initialize oled screen
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
initWiFi(); // Initialize wifi
initAHT(); // Initialize AHT sensor
pinMode(bCLK, INPUT);
pinMode(bDT, INPUT);
pinMode(bSW, INPUT_PULLUP);
Time_aht = millis();
Time_lim = millis();
Time_oled = millis();
Time_fb = millis();
attachInterrupt(digitalPinToInterrupt(bCLK), isrAB, RISING);
}
void loop() {
static int lastCtr;
static unsigned long SpamTimer;
int Counter;
noInterrupts ();
Counter = lim;
interrupts ();
if (lastCtr != Counter) {
if (Firebase.ready() && signupOK) {
Firebase.RTDB.setInt(&fbdo, "test/lim", Counter);
if (millis() > Time_fb){
Serial.println("lim");
Serial.println(lim);
}
}
lastCtr = Counter;
Time_fb = getStartTime(1000);
}
//Firebase.RTDB.setInt(&fbdo, "test/term", temperature);
//Firebase.RTDB.setInt(&fbdo, "test/hum", humidity);
//stringVal=String(lim);
//Firebase.RTDB.setInt(&fbdo, "test/lim", lim);
//if(Firebase.RTDB.getString(&fbdo, "/test/lim")){
// if (fbdo.dataType() == "string") {
// stringValue = fbdo.stringData();
// newfb=stringValue.toInt();
// }
// }
// haschanged(newfb);
// Time_fb = getStartTime(1000);
//}
//TEMP DATA
if(millis() > Time_aht){
sensors_event_t humi, temp;
aht.getEvent(&humi, &temp);// populate temp and humidity objects with fresh data
temperature=temp.temperature;
humidity=humi.relative_humidity;
Time_aht = getStartTime(3000);
}
//if(millis() > Time_lim)
// {
// Time_lim = getStartTime(100);
// }
if(millis() > Time_oled)
{
drawUpdateOLED(temperature, humidity, Counter);
Time_oled = getStartTime(1000);
}
}
After turning the rotary encoder a few times, the value of the button goes to firebase. and after a while it becomes the initial value 10 again