[img]C:\Users\admin\Desktop\111.svg[/img]
- const int keyPin=21;//change 21 to 2 when using arduino uno
- int num=0;
- boolean flag=false;
- void echo()
- {
- flag=true;
- num++;
- }
- void setup()
- {
- Serial.begin(9600);
- pinMode(keyPin,INPUT);
- attachInterrupt(keyPin,echo,FALLING);//change keyPin to 0 when using arduino uno
- }
- void loop()
- {
- if(flag)
- {
- Serial.println(num);
- flag=false;
- }
- }
It is unexpected the "num" increased many times when clicking the button only once.
At this point, I tested it with arduino uno, it turned out that the "num" had only increased once when clicking the button once. The result is very well when using arduino uno.
Why is the same procedure so different in results? I think it is come from the "attachInterrupt()" in ESP32-arduino. It maybe a bug in ESP32-arduino of attachInterrupt().
Have others found similar problems?
Best regards.