Sakis Kasampalis
/
human-detector
using just a pot and tinfoil
Revision 0:6e8da69e6440, committed 2016-11-19
- Comitter:
- faif
- Date:
- Sat Nov 19 22:38:58 2016 +0000
- Commit message:
- Human detector
Changed in this revision
diff -r 000000000000 -r 6e8da69e6440 human_detector.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/human_detector.cpp Sat Nov 19 22:38:58 2016 +0000 @@ -0,0 +1,37 @@ +#include "mbed.h" +#include "human_detector.h" + +static const char CLS[] = "\x1B[2J"; // VT100 erase screen +static const char HOME[] = "\x1B[H"; // VT100 home +static const float DEBOUNCING_DELAY = 0.2; +enum state { OFF = 0, ON = 1 }; + +int main() +{ + clear_screen(); + while (true) + { + init(potout, led); + while (!potin) {} // wait until there's a pot (capacitor) charge + alarm(led); + } +} + +void clear_screen() +{ + pc.printf(CLS); + pc.printf(HOME); +} + +void init(DigitalOut& pot, DigitalOut& led) +{ + pot = ON; + led = OFF; +} + +void alarm(DigitalOut& led) +{ + led = ON; + pc.printf("Human detected\r\n"); + wait(DEBOUNCING_DELAY); +}
diff -r 000000000000 -r 6e8da69e6440 human_detector.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/human_detector.h Sat Nov 19 22:38:58 2016 +0000 @@ -0,0 +1,14 @@ +#ifndef HUMAN_DETECTOR_H +#define HUMAN_DETECTOR_H + +DigitalIn potin(p20); +DigitalOut potout(p19); +DigitalOut led(LED4); + +Serial pc(USBTX, USBRX); + +void clear_screen(); +void init(DigitalOut& pot, DigitalOut& led); +void alarm(DigitalOut& led); + +#endif \ No newline at end of file
diff -r 000000000000 -r 6e8da69e6440 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Nov 19 22:38:58 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/0ab6a29f35bf \ No newline at end of file