Please share sample code for AN EXTERNAL INTRRUPT Digital INPUT WHICH YOU USE TO COUNT THE NUMBER OF INPUT PULSES AND STORE THE COUNT IN A GLOBAL VARIABLE
Thanks
Please share sample code for AN EXTERNAL INTRRUPT Digital INPUT WHICH YOU USE TO COUNT THE NUMBER OF INPUT PULSES AND STORE THE COUNT IN A GLOBAL VARIABLE
Thanks
Hello,
#include "mbed.h"
InterruptIn button(BUTTON1); // like an external source of pulses
/* in some cases may be necessary use also keyword volatile
for avoid compiler optimization */
volatile int counter = 0;
void pressed(){
counter++;
}
int main()
{
printf("Interrupt counter example\n");
// fall or rise
button.fall(callback(&pressed));
//button.rise(callback(&pressed));
while (true) {
thread_sleep_for(1000);
printf("Current counter value is %d\n",counter);
}
}
BR, Jan