Vjezba 2 iz PURSA.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
JosipLupinski
Date:
Wed Oct 26 12:42:14 2016 +0000
Commit message:
Ovo je vje?ba 2.

Changed in this revision

digitalni_ulaz_pullDown.cpp Show annotated file Show diff for this revision Revisions of this file
digitalni_ulaz_pullNone.cpp Show annotated file Show diff for this revision Revisions of this file
digitalni_ulazi.cpp Show annotated file Show diff for this revision Revisions of this file
digitalni_ulazi_pullNone.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
open_drain_mode_v1.cpp Show annotated file Show diff for this revision Revisions of this file
open_drain_mode_v2.cpp Show annotated file Show diff for this revision Revisions of this file
standardLED_RED_GREEN.cpp Show annotated file Show diff for this revision Revisions of this file
--- /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;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/digitalni_ulaz_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(PullNone);  //Bog zna kaj bu, nepredvidivo se ponaša
+    
+    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;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/digitalni_ulazi.cpp	Wed Oct 26 12:42:14 2016 +0000
@@ -0,0 +1,29 @@
+#include "mbed.h"
+ 
+DigitalOut green(p5);
+DigitalOut red(p6);
+DigitalIn switchInput(p10);
+ 
+int main() {
+    int switchState;
+    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;
+        }
+    }
+}
--- /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;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 26 12:42:14 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open_drain_mode_v1.cpp	Wed Oct 26 12:42:14 2016 +0000
@@ -0,0 +1,16 @@
+#include "mbed.h"
+ 
+DigitalInOut green(p22, PIN_OUTPUT, OpenDrain, 1);
+DigitalInOut red(p21, PIN_OUTPUT, OpenDrain, 1);
+ 
+int main() {
+
+    while(true) {
+        green = 0;
+        red = 1;
+        wait(0.5);
+        green = 1;
+        red = 0;
+        wait(0.5);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open_drain_mode_v2.cpp	Wed Oct 26 12:42:14 2016 +0000
@@ -0,0 +1,23 @@
+#include "mbed.h"
+ 
+DigitalInOut green(p22); 
+DigitalInOut red(p21);
+int main() {
+    
+    green.output();
+    green.mode(OpenDrain);
+    green = 1;
+    
+    red.output();
+    red.mode(OpenDrain);
+    red = 1;
+    
+    while(true) {
+        green = 0;
+        red = 1;
+        wait(0.5);
+        green = 1;
+        red = 0;
+        wait(0.5);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/standardLED_RED_GREEN.cpp	Wed Oct 26 12:42:14 2016 +0000
@@ -0,0 +1,15 @@
+#include "mbed.h"
+ 
+DigitalOut green(p5);
+DigitalOut red(p6);
+ 
+int main() {
+    while(true) {
+        green = 1;
+        red = 0;
+        wait(0.5);
+        green = 0;
+        red = 1;
+        wait(0.5);
+    }
+}
\ No newline at end of file