Næþ'n Lasseter / Mbed 2 deprecated DoorTimer

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 Timer t;
00004 DigitalOut idle(LED1);
00005 DigitalOut busy(LED2);
00006 DigitalOut open(p10);
00007 InterruptIn start(p15);
00008 Serial pc(USBTX, USBRX);
00009 
00010 int led=0;
00011 
00012 void onfall() {
00013     pc.printf("Door Opened... ");
00014     t.start();
00015     open=1;
00016     idle=0;
00017     led=1;
00018 }
00019 
00020 void onrise() {
00021     t.stop();
00022     open=0;
00023     pc.printf("Door Closed at %f\r\n", t.read());
00024     t.reset();
00025     busy=0;
00026     led=0;
00027 }
00028 
00029 int main() {
00030     open=busy=idle=0;
00031     start.fall(&onfall);
00032     start.rise(&onrise);
00033     while(1) {
00034         if(led) {
00035             busy = !busy;
00036         } else {
00037             idle = !idle;
00038         }
00039         wait(1);
00040     }
00041 }