Versie 2 - Vorm state machine aangenomen

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lennartgroen
Date:
Sun Mar 25 23:08:59 2018 +0000
Parent:
0:ec163fd43fec
Commit message:
Switches toegevoegd voor ring lus schakeling;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Mar 25 22:35:49 2018 +0000
+++ b/main.cpp	Sun Mar 25 23:08:59 2018 +0000
@@ -8,6 +8,8 @@
 */
 
 #include <mbed.h>
+DigitalIn ring_NZ = D4;
+DigitalIn ring_OW = D2;
 
 struct lichtkleur {             // Struct voor beheren LED kleuren van stoplicht
     float val_rood, val_groen, val_blauw;
@@ -19,6 +21,8 @@
     STATE_NZ_ORANJE,
     STATE_OW_GROEN,
     STATE_OW_ORANJE,
+    STATE_RING_NZ,
+    STATE_RING_OW,
 };
 
 // Defineren van ledkleuren voor RGB LED - Buiten class omdat dit compiling errors geeft
@@ -68,7 +72,7 @@
                 break;
             case STATE_NZ_GROEN:
                 stoplicht_nz.set_groen();
-                if(timer1.read() >= 5) {
+                if(timer1.read() >= 19) {
                     stoplicht_state = STATE_NZ_ORANJE;
                     timer1.reset();
                 }
@@ -83,7 +87,7 @@
                 break;
             case STATE_OW_GROEN:
                 stoplicht_ow.set_groen();
-                if(timer1.read() >= 5) {
+                if(timer1.read() >= 19) {
                     stoplicht_state = STATE_OW_ORANJE;
                     timer1.reset();
                 }
@@ -96,10 +100,31 @@
                     timer1.reset();
                 }
                 break;
+             case STATE_RING_NZ:
+          
+                if(timer1.read() >= 3) {
+                    stoplicht_state = STATE_OW_ORANJE;
+                    timer1.reset();
+                }
+                case STATE_RING_OW:
+         
+                if(timer1.read() >= 3) {
+                    stoplicht_state = STATE_NZ_ORANJE;
+                    timer1.reset();
+                }
+                break;
             default:
                 stoplicht_state = STATE_ROOD;
                 break;
         }
+        if (ring_NZ == 1 && stoplicht_state == STATE_OW_GROEN) {
+               timer1.reset();
+            stoplicht_state = STATE_RING_NZ;
+        }
+        if (ring_OW == 1 && stoplicht_state == STATE_NZ_GROEN){
+               timer1.reset();
+            stoplicht_state = STATE_RING_OW;
+        }
 
     }