Vjezba 2 iz PURSA.
Dependencies: mbed
Diff: digitalni_ulaz_pullDown.cpp
- Revision:
- 0:0f35d76ae855
diff -r 000000000000 -r 0f35d76ae855 digitalni_ulaz_pullDown.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/digitalni_ulaz_pullDown.cpp Wed Oct 26 12:42:14 2016 +0000 @@ -0,0 +1,32 @@ +#include "mbed.h" + +DigitalOut green(p5); +DigitalOut red(p6); +DigitalIn switchInput(p10); + +int main() { + + int switchState; + switchInput.mode(PullDown); //ground interno doveden na p10, tj. ne moramo ga fizčki spojiti na p10 + + while(true) { + switchState = switchInput; // citanje stanja ulaza samo jednom u prolazu petlje + if(switchState == 0) { + green = 0; + red = 1; + wait(0.5); + red = 0; + wait(0.5); + } else if (switchState == 1) { + red = 0; + green = 1; + wait(0.5); + green = 0; + wait(0.5); + } else { + // nemoguc slucaj + red = 1; + green = 1; + } + } +}