Javier Sanchez Peña
/
Prueva_microswitch_pullup
use a digital input in pull up mode to read a signal from a microswitch and toggle a LED
main.cpp@0:9330a73f2ea2, 2017-05-14 (annotated)
- Committer:
- javierjsp
- Date:
- Sun May 14 19:19:34 2017 +0000
- Revision:
- 0:9330a73f2ea2
v1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
javierjsp | 0:9330a73f2ea2 | 1 | #include "mbed.h" |
javierjsp | 0:9330a73f2ea2 | 2 | |
javierjsp | 0:9330a73f2ea2 | 3 | DigitalIn micro(D0, PullUp); |
javierjsp | 0:9330a73f2ea2 | 4 | DigitalOut myled(LED1); |
javierjsp | 0:9330a73f2ea2 | 5 | |
javierjsp | 0:9330a73f2ea2 | 6 | int main() { |
javierjsp | 0:9330a73f2ea2 | 7 | while(1) |
javierjsp | 0:9330a73f2ea2 | 8 | { |
javierjsp | 0:9330a73f2ea2 | 9 | if (micro) |
javierjsp | 0:9330a73f2ea2 | 10 | { |
javierjsp | 0:9330a73f2ea2 | 11 | myled = 0; // LED is ON |
javierjsp | 0:9330a73f2ea2 | 12 | } |
javierjsp | 0:9330a73f2ea2 | 13 | else |
javierjsp | 0:9330a73f2ea2 | 14 | { |
javierjsp | 0:9330a73f2ea2 | 15 | myled = 1; // LED is OFF |
javierjsp | 0:9330a73f2ea2 | 16 | } |
javierjsp | 0:9330a73f2ea2 | 17 | } |
javierjsp | 0:9330a73f2ea2 | 18 | } |