Vjezba 2 iz PURSA.

Dependencies:   mbed

Revision:
0:0f35d76ae855
diff -r 000000000000 -r 0f35d76ae855 digitalni_ulazi_pullNone.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/digitalni_ulazi_pullNone.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(PullUp);  //iskopčati GND i onda zelena svijetli stalno
+    
+    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;
+        }
+    }
+}