// Thia is the interrupt in respect of the ADXL chip and declared at global scope //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void IRAM_ATTR falling() {//this is pin 14 connected to interrupt int 1 mytime = millis();//grab the time and store in global varaible GLOBAL_ADXL_FLAG=true;//just set the flag and exit detachInterrupt(digitalPinToInterrupt(CFG_PIN));//kill //We will let the loop deal with it } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // // //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void IRAM_ATTR WirelessUp() {//this is pin 13 connected to push button detachInterrupt(digitalPinToInterrupt(WIRE_PIN));//kill //WIRELESS_FLAG//THIS IS FLAG TO SET FOR REMOTE ACCESS Serial.println("interrupt on 13!!!"); WIRELESS_FLAG=true;//set the flag and exit gets reset in loop //We will let the loop deal with it } Note CFG_PIN and WIRE_PIN were previously declared here int WIRE_PIN = 13;//change this mapping for remote access and upload int CFG_PIN = 14;//change this mapping for serial2 on 16 //now in setup attach them to the pins pinMode(WIRE_PIN, INPUT_PULLUP);//cfg pin will be pin 13 to catch the interrupt for remote attachInterrupt(digitalPinToInterrupt(WIRE_PIN), WirelessUp, FALLING);//function is called WirelessUp pinMode(CFG_PIN, INPUT_PULLUP);//cfg pin will be pin 14 to catch the interrupt attachInterrupt(digitalPinToInterrupt(CFG_PIN), falling, FALLING);//function is called falling GLOBAL_ADXL_FLAG and WIRELESS_FLAG were also declared previously as bools bool GLOBAL_ADXL_FLAG=0;//interrupt for adxl bool WIRELESS_FLAG=0;//INTERRUPT FOR REMOTE ACCESS Note the use of void IRAM_ATTR to make sure these remain static and unaltered. In main we deal with it like so: if(WIRELESS_FLAG==true)//test this flag { stopgps=true;//stop the gps func Serial.println("stoppedGPS!!"); altstatus=false; satstatus=false; speedstatus=false; latlong=false;//disable the saving of details on disk when gps stopped WiFi.mode(WIFI_OFF); delay(2000);//wait a bit WiFi.begin(); // do other stuff //and for the ADXL interrupt if(GLOBAL_ADXL_FLAG==true)//interrupt triggered for some reason { I2CiSbUSY=true; GLOBAL_ADXL_FLAG=false;//reset it writeToI2C(ADXL345_DEVICE,ADXL345_INT_ENABLE ,0x00);//disable the interrupts readFromI2C(ADXL345_DEVICE,ADXL345_INT_SOURCE,1,&interrupt_byte);//find out the source Serial.print("status interrupt= "); Serial.println(interrupt_byte,HEX); testbyte=interrupt_byte & MASK_TAP; if(testbyte) { Serial.println("*** BIG SHOCK DETECTED!!***"); display.setCursor(0,0); display.clearDisplay(); display.display(); display.print("BIG SHOCK DETECTED!!"); display.display(); display.setCursor(0,20); display.print("OOH THAT HURT!!"); display.display(); //delay(1000); WriteShockData(); listDir(SD, "/", 0); writeToI2C(ADXL345_DEVICE,ADXL345_INT_ENABLE ,0x48);//reenable the interrupts after flag set regardless // attachInterrupt(digitalPinToInterrupt(CFG_PIN), falling, FALLING);//function is called falling I2CiSbUSY=false;//start the display }//the type of interrupt //note also the use of detach interrupt to stop further interrupts while servicing