Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By nimaaryamehr
#69121 Hello
In this app i used a rising interruption
I want to add a Falling interruption with that same pin (pin2)
That is, if an interruption falling, go to another program
How do i do this
Code: Select all#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>


const byte interruptPin = 2;

const char* BASEURI="http://telegramiotbot.com/api/notify?token=";
const char* TOKEN_NOTIFY="XXXXXXXXXX";


bool interrupted=false;
/*
    interrupt handler
*/
void inputChanged(){
    interrupted=true;
}
void notify(const char* token){
    HTTPClient http;

    http.begin(String(BASEURI) + token);

    int httpCode = http.GET();

}




void setup() {
   
    WiFiManager wifiManager;
    //wifiManager.resetSettings();
    wifiManager.autoConnect("SmartHome");
   
    pinMode(interruptPin, INPUT_PULLUP);
    attachInterrupt(digitalPinToInterrupt(interruptPin), inputChanged, RISING);
}

void loop() {
    if(interrupted){
        if((WiFi.status() == WL_CONNECTED)) {
            notify(TOKEN_NOTIFY);
            interrupted=false;
        }
    }
}

User avatar
By QuickFix
#69137 You can't: you can only attach one interrupt to a GPIO.

You can, however, create a "CHANGE" interrupt and determine whether the GPIO down or up in the interrupt code. :idea:
User avatar
By nimaaryamehr
#69158
QuickFix wrote:You can't: you can only attach one interrupt to a GPIO.

You can, however, create a "CHANGE" interrupt and determine whether the GPIO down or up in the interrupt code. :idea:


You can explain more
Or take an example
User avatar
By QuickFix
#69212 Sure. :)

Pin definition:
Code: Select all#define interruptPin 2

The interrupt function:
Code: Select allvoid switching() {
  noInterrupts();
  if (digitalRead(interruptPin) == HIGH) {
    // Do something when HIGH
  } else {
    // Do something when LOW
  }
  interrupts();
}

Somewhere in your setup():
Code: Select allvoid setup() {
  // Some setup things...
  attachInterrupt(digitalPinToInterrupt(interruptPin), switching, CHANGE);
  // Some more setup things...
}