Analog Interrupts
Posted: Tue Jun 01, 2021 7:03 pm
Hello,
I am working with the MQ-2 smoke sensor and am trying to set it up for its analog output to trigger an interrupt.
I got code working that has a capacitive touch button (wire) trigger an interrupt:
But this does not work with the MQ-2 smoke sensor.
I was wondering if anyone knows how to set up general-purpose analog interrupts.
thanks
I am working with the MQ-2 smoke sensor and am trying to set it up for its analog output to trigger an interrupt.
I got code working that has a capacitive touch button (wire) trigger an interrupt:
Code: Select all
/*
* Capacitive touch code using ESP32 GPIO4 (TOUCH0)
*/
const int touchPIN = 4; //Touch button PIN
const int n = 50; //Number of averages for threshold calc
bool interruptFlag = false;
int thresholdValue = 0; //Used to detect when pressed
int touchSensorValue = 0; //Holds touch value
int TEMP = 0;
int thresholdCalc(){
for(int i=0; i<n; i++){
touchSensorValue = touchRead(touchPIN);
TEMP += touchSensorValue;
}//end for
return (TEMP/(n*2)); //Sets thresholdValue to 1/2 the average measured value
}//end thresholdCalc
void IRAM_ATTR interruptRoutine(){ //Interrupt routine
interruptFlag = true;
}//end interruptRoutine
void setup(){
Serial.begin(115200);
delay(1000);
thresholdValue = thresholdCalc();
touchAttachInterrupt(touchPIN, interruptRoutine, thresholdValue); //Setup the interrupt
}//end setup
void loop(){
if(interruptFlag){
interruptFlag = false;
Serial.println("Touch detected");
//Serial.println(measureButton());
}//end if
delay(50);
}//end loop
But this does not work with the MQ-2 smoke sensor.
I was wondering if anyone knows how to set up general-purpose analog interrupts.
thanks