Simple program showing code running based on switch position/pin state

Dependencies:   mbed

main.cpp

Committer:
simon
Date:
2012-06-10
Revision:
0:0ad077525ca2

File content as of revision 0:0ad077525ca2:

// run some code based on switching a switch (changing a pin state)

#include "mbed.h"

DigitalIn toggle(p5);
DigitalOut myled(LED1);

void toggle_on() {
    for(int i=0; i<10; i++) {
        myled = !myled;
        wait(0.2);
    }
}

void toggle_off() {
    // do nothing
}

int main() {
    while(1) {
        while(!toggle); // wait while toggle == 0
        toggle_on();
        while(toggle);  // wait while toggle == 1
        toggle_off();
    }
}