a program with changes the between two states with the press of a button
Revision 1:a070f8a0bf04, committed 2015-11-03
- Comitter:
- wehner334
- Date:
- Tue Nov 03 15:32:39 2015 +0000
- Parent:
- 0:26da192b707b
- Commit message:
- tested and working with changes;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Nov 03 12:25:44 2015 +0000
+++ b/main.cpp Tue Nov 03 15:32:39 2015 +0000
@@ -1,9 +1,9 @@
#include "mbed.h"
-
+
InterruptIn mybutton(USER_BUTTON);//generates an object named mybutton out of the class InterruptIn
DigitalOut myled(LED1); //
-
-volatile float delay = 1.0; // 1 sec of delay in the delay
+
+volatile float delay = 4.0; // 1 sec of delay in the delay
volatile bool Pressedornot=false; // global variable with is updated by the interrupt function
/*function pressed() is called than a interrupt is generated by the external interrupt when the userbutton is pressed
@@ -12,22 +12,26 @@
void pressed()
{
if (Pressedornot==false)
- Pressedornot=true;
+ Pressedornot=true;
else
- Pressedornot=false;
+ Pressedornot=false;
}
-
+
int main()
{
mybutton.fall(&pressed);//activates the interrupt then a falling edge is detected on the pin
while (1) {
- if(Pressedornot==false)
- {myled = !myled;
- wait(delay);
+ while(Pressedornot==false) {
+ myled = !myled;
+ for(int i=0;i<1000000;i++)//
+ {wait_us(1);
+ if(Pressedornot==true)
+ {break;}
+ }
+ } while( Pressedornot==true )
+ {
+ myled=true;
}
- else
- {myled=true;
- }
-
+
}
}