Arduino buton okuma ve işleme

Kod:
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>   // Universal Telegram Bot Library written by Brian Lough: https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
#include <ArduinoJson.h>

const char* ssid = "";
const char* password = "";

// Initialize Telegram BOT    // your Bot Token (Get from Botfather)
#define BOTtoken "" // ""

// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can message you
#define CHAT_ID ""

WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

 const int ledPin = 2;

// Giriş Sinyal pinleri (en yeni düzen)
 const int odaPin = 16;
// const int doorPin = 17; 
// const int salonPin = 18;
// const int yedekPin = 19;


bool ledState = LOW;

int debounce_Limit = 10;
int od = 0; // butonun önceki durumu
int sd = 0; // butonun şimdiki durumu
int td = 0; // butonun temiz durumu
int aos = 0; // aynı olma sayısı
    


void setup() {
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);

  // set initial LED state
  digitalWrite(ledPin, td);
   pinMode(odaPin, INPUT_PULLUP);
//   pinMode(salonPin, INPUT_PULLUP);
//   pinMode(doorPin, INPUT_PULLUP);
//   pinMode(yedekPin, INPUT_PULLUP);

  // Connect to Wi-Fi
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }
  // Print ESP32 Local IP Address
  Serial.println(WiFi.localIP());

  bot.sendMessage(CHAT_ID, "Bot started 21_DB1", "");
                
} // xxxxxxxxxxxxxxxxxxxx  SET UP SONU  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx




void loop() {// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

   delay(1);

   od = sd;
   sd = digitalRead(odaPin);
   if (sd == od)
   {
      if (aos == debounce_Limit)
      {
         // 10 defa peş peşe aynı değer gördük, bu buton hakkaten basıldı.
         // yeni durumu td ye kaydet ve tekrar temiz buton aramaya başla
         aos = 0;
         td = sd;
         digitalWrite(ledPin,td);
         if (td){
          Serial.println("ODADA OLAY1");}
          else {
          Serial.println("ODADA OLAY2");}
         //bot.sendMessage(CHAT_ID, "ODADA OLAY" , "");}
      }
      else
      {
         // daha 10 defa aynı değeri göremedik, saymaya devam et
         ++aos;
      }
   }
   else
   {
     // Şimdiki değer öncekinden farklı, sayacı sıfırla ve tekrar 10 tane eşit değer görmeyi bekle
      aos = 0;
   }
 
   }
 
Kesme ile yapmak istediğinizi söylemiştiniz???
doğru. bu projeyi 2 aydır çalışıyorum. çıkış noktamda kesme vardı. uzun süre de öyle kaldı. Ancak temiz olmayan ( ve bazen de anlamsız ) sonuçlar almam yüzünden zaman zaman kesme den vaz geçtiğim oldu. Bir çok yol denedim başaramadım.
şu anki düşüncem kesme + debounce olması gerektiği. Sizin de bu konuda düşüncenizi bilmek isterim.
 

Forum istatistikleri

Konular
128,149
Mesajlar
915,474
Kullanıcılar
449,891
Son üye
Ercan29

Yeni konular

Geri
Üst