Button and counter application counter=2 not working

Dependencies:   mbed

Fork of Test_button_interrupt by BITS IOT PGP 2017-18

Committer:
Rahul091093
Date:
Wed Jun 20 17:22:31 2018 +0000
Revision:
2:42d48cf3ada3
Parent:
1:7bb6b5b519b5
NEW_application

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rahul091093 0:90db2a2ace62 1 #include "mbed.h"
Rahul091093 0:90db2a2ace62 2 //Application is to store the count of push button in a counter and perform the application counter value
Rahul091093 0:90db2a2ace62 3 //Configuring push button
Rahul091093 0:90db2a2ace62 4
Rahul091093 0:90db2a2ace62 5 InterruptIn StopButton(PA_0);
Rahul091093 0:90db2a2ace62 6
Rahul091093 0:90db2a2ace62 7 int ButtonDetect = 0;
Rahul091093 0:90db2a2ace62 8
Rahul091093 0:90db2a2ace62 9 void StopButtonISR()
Rahul091093 0:90db2a2ace62 10 {
Rahul091093 0:90db2a2ace62 11 ButtonDetect = 1;
Rahul091093 0:90db2a2ace62 12 }
Rahul091093 0:90db2a2ace62 13
Rahul091093 0:90db2a2ace62 14 DigitalOut myled(PD_12);
Rahul091093 0:90db2a2ace62 15
Rahul091093 0:90db2a2ace62 16 int main() {
Rahul091093 0:90db2a2ace62 17
Rahul091093 0:90db2a2ace62 18 //interrupt occurred at falling edge
Rahul091093 0:90db2a2ace62 19
Rahul091093 0:90db2a2ace62 20 StopButton.fall(&StopButtonISR);
Rahul091093 0:90db2a2ace62 21 int counter=0;
Rahul091093 0:90db2a2ace62 22
Rahul091093 0:90db2a2ace62 23 while(1)
Rahul091093 0:90db2a2ace62 24 {
Rahul091093 2:42d48cf3ada3 25 if(ButtonDetect==1)
Rahul091093 0:90db2a2ace62 26 counter++;
Rahul091093 2:42d48cf3ada3 27
Rahul091093 0:90db2a2ace62 28 if(counter==1)// on count 1 Led output will be 1
Rahul091093 0:90db2a2ace62 29 {
Rahul091093 0:90db2a2ace62 30 myled = 1;
Rahul091093 2:42d48cf3ada3 31 wait(0.2);
Rahul091093 2:42d48cf3ada3 32 myled = 0;
Rahul091093 2:42d48cf3ada3 33 wait(0.2);
Rahul091093 0:90db2a2ace62 34 }
Rahul091093 2:42d48cf3ada3 35 else
Rahul091093 2:42d48cf3ada3 36 if(counter==2)// on count 2 Led output will be 0
Rahul091093 0:90db2a2ace62 37 {
Rahul091093 2:42d48cf3ada3 38 myled = !myled;
Rahul091093 0:90db2a2ace62 39 }
Rahul091093 0:90db2a2ace62 40 if(counter >= 3)
Rahul091093 0:90db2a2ace62 41 counter =0;//counter reset
Rahul091093 2:42d48cf3ada3 42
Rahul091093 0:90db2a2ace62 43
Rahul091093 0:90db2a2ace62 44 }
Rahul091093 0:90db2a2ace62 45 }
Rahul091093 2:42d48cf3ada3 46