touch中断和外部中断
#include <Arduino.h>
#define EXT_ISR_MODE 1
//定义中断的mode:
//1:touch中断,执行touchevent
//2:外部中断
// put function declarations here:
// int myFunction(int, int);
void TouchEvent();
void PinIntEvent();
void setup() {
// put your setup code here, to run once:
// pinMode(32, OUTPUT);
Serial.begin(115200);
#if 1==EXT_ISR_MODE
touchAttachInterrupt(T0,TouchEvent,40);
// 设置GPIO04,函数指针TouchEvent,阈值40
#elif 2==EXT_ISR_MODE
pinMode(32,INPUT_PULLUP);
attachInterrupt(0,PinIntEvent,FALLING);
#endif
}
void loop() {
// // put your main code here, to run repeatedly:
// digitalWrite(32, HIGH); // turn the LED on (HIGH is the voltage level)
// delay(1000); // wait for a second
// digitalWrite(32, LOW); // turn the LED off by making the voltage LOW
// delay(1000);
#if 0==EXT_ISR_MODE
Serial.printf("touch:%d\r\n",touchRead(T0));
#endif
delay(20);
}
// // put function definitions here:
// int myFunction(int x, int y) {
// return x + y;
// }
// 1.Touch中断事件
void TouchEvent()
{
Serial.printf("TouchEvent.\r\n");
}
// 2.外部中断事件
void PinIntEvent()
{
Serial.printf("PinIntEvent.\r\n");
}