Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

two GPIO Handlers enabled?

mtraxmtrax Canberra
edited May 13 in Mongoose OS

I have a some code listening for two Reed switches on PIN5 and PIN14
for some reason I can't see to get both to fire , is it possible to have two handlers on different GPIO pins?

eg The code is mjs running on a NodeMCU / ESP8266

let rc=-1;
// listen for Sensor#1 GPIO PIN changes
rc=GPIO.set_int_handler(DOORS[0].sensorpin, GPIO.INT_EDGE_ANY, function(pin) {
   print('interrupt handler: PIN=', pin);
   for (let i = 0; i < DOORS.length; i++) {
    // print('interrupt handler: i=', DOORS[i].sensorpin);
    if (pin ===  DOORS[i].sensorpin) {
      //checkDoor(DOORS[i].sensorpin);
      DOORS[i].doorstate = checkDoor(DOORS[i]);
    }
  }

}, null);

print('handler=',rc ,'enable sensor PIN:', DOORS[0].sensorpin);
rc= GPIO.enable_int(DOORS[0].sensorpin);
print('enable handler=',rc);

// listen for Sensor#2 GPIO PIN changes
rc=GPIO.set_int_handler(DOORS[1].sensorpin, GPIO.INT_EDGE_ANY, function(pin) {
   print('interrupt handler: PIN=', pin);
   for (let i = 0; i < DOORS.length; i++) {
     print('interrupt handler: i=', DOORS[i].sensorpin);
    if (pin ===  DOORS[i].sensorpin) {
      //checkDoor(DOORS[i].sensorpin);
      DOORS[i].doorstate = checkDoor(DOORS[i]);
    }
  }

}, null);

print('handler=',rc ,'enable sensor PIN:', DOORS[1].sensorpin);
GPIO.enable_int(DOORS[1].sensorpin);
print('enable handler=',rc);

Comments

Sign In or Register to comment.