a program with changes the between two states with the press of a button

Dependencies:   mbed

main.cpp

Committer:
wehner334
Date:
2015-11-03
Revision:
0:26da192b707b
Child:
1:a070f8a0bf04

File content as of revision 0:26da192b707b:

#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 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
it alters the Pressedornot variable from true to false
*/
void pressed()
{
    if (Pressedornot==false)
       Pressedornot=true; 
    else
       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);
        }
        else
        {myled=true;
            }
        
    }
}