Jeff Nguyen / Mbed 2 deprecated Traffic_Light

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
JN482
Date:
Tue Nov 20 12:59:19 2018 +0000
Parent:
2:37d5e9d92b66
Commit message:
Finalised Traffic-lights;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Nov 11 16:38:24 2018 +0000
+++ b/main.cpp	Tue Nov 20 12:59:19 2018 +0000
@@ -2,7 +2,6 @@
 This project includes both the safe, unsafe sequences, pedestrian crossing, and a buzzer.
 The Assignment task is to create both the safe and unsafe traffic light sequence.
 */
-
 #include <mbed.h> // importing the mbed library to allow to use input and output fuctions 
 #include <SevenSegment.h>
 DigitalOut Onboard(LED1);//declaring the onboard led as Onboard
@@ -15,17 +14,14 @@
 InterruptIn button (USER_BUTTON); //I will be using the onboard button as a pedestrian button
 InterruptIn Switch(D15);//I will be using an external wire to act as a button.
 //DigitalOut Buzzer(D10);//Buzzer
-
 bool pedest = false, unsafe = false; //setting up 2 true or false variables and a integer counter
 int counter = 0;
-
 void pedestrians()
 //Declaring a procedure for changing a variable for pedestrians
 {
     pedest = true;
     Onboard = 1;
 }
-
 void reset()
 {
     //start reset procedure.
@@ -40,7 +36,6 @@
     ResetSeg(); // calls the resetSeg procedure in the SevenSegment.h
     //All Lights are switched off. (Procedure Ends return to main)
 }//End reset procedure.
-
 void safe()
 {
     if (unsafe == false) {
@@ -51,13 +46,14 @@
         reset();
     }
 }
-
 void sequence(int unsafe)
 // Declaring a procedure for sequence. 2 Arguments are recieved - unsafe and pedestrians
-{
+{   
     //Start sequence procedure.
     if(unsafe == true) {
         //  Sequence      TRAFFIC 1, TRAFFIC 2
+        reset();
+        ResetSeg();
         RLED = 1;  //     RED ON     RED OFF
         GGLED = 1; //     AMBER OFF  AMBER OFF
         wait(5);   //     GREEN OFF  GREEN ON
@@ -79,12 +75,11 @@
         AALED = 1; //     GREEN OFF   GREEN OFF
         wait(2);
         //----------------------------------------------
-        reset();          /*RRLED = 0; //    RED OFF     RED OFF
-                          ALED = 0;   //     AMBER OFF   AMBER OFF
-                          AALED = 0;  //     GREEN OFF   GREEN OFF
-                            This sequence is the same as reset()*/
+        reset();//This sequence is the same as reset()*/
     } else if(unsafe == false) { //if in safemode run this sequence.
         //  Sequence          TRAFFIC 1, TRAFFIC 2
+        reset();
+        ResetSeg();
         RLED = 1;  //     RED ON     RED OFF
         GGLED = 1; //     AMBER OFF  AMBER OFF
         wait(5);   //     GREEN OFF  GREEN ON
@@ -100,47 +95,18 @@
         AALED = 0;
         wait(2);
         if (pedest == true) {
-            Buzzer = 1; // Turns on buzzer, however due to the fact that the Nucleo F411RE only has 15 DigitalOut of which 13 is usable as D0 and D1 are reseved pins.
-            ResetSeg(); //Calls the ResetSeg procedure to turn OFF all of the segments
-            nine(); //Call the procedure to display number 9
-            wait(1);
-            ResetSeg();
-            eight();//Call the procedure to display number 8
-            wait(1);
-            ResetSeg();
-            seven();//Call the procedure to display number 7
-            wait(1);
-            ResetSeg();
-            six();//Call the procedure to display number 6
-            wait(1);
-            ResetSeg();
-            five();//Call the procedure to display number 5
-            wait(1);
-            ResetSeg();
-            four();//Call the procedure to display number 4
-            wait(1);
-            ResetSeg();
-            three();//Call the procedure to display number 3
-            wait(1);
-            ResetSeg();
-            two();//Call the procedure to display number 2
-            wait(1);
-            ResetSeg();
-            one();//Call the procedure to display number 
-            wait(1);
-            ResetSeg();// The final Reset turns OFF all the segments 
+            //Buzzer = 1; // Turns on buzzer, however due to the fact that the Nucleo F411RE only has 15 DigitalOut of which 13 is usable as D0 and D1 are reseved pins.
+            ResetSeg();nine();wait(1);ResetSeg();eight();wait(1);ResetSeg();seven();wait(1);ResetSeg();six();wait(1);ResetSeg();five();wait(1);
+            ResetSeg();four();wait(1);ResetSeg();three();wait(1);ResetSeg();two();wait(1);ResetSeg();one();wait(1);Onboard = 0; ;ResetSeg();
             pedest = false;// The boolean variable is reset back to false
-            Onboard = 0; // The Onboard LED is turned OFF
-            // condition of counter is while the counter is less than or equal to 20
         }
         //----------------------------------------------
         GLED = 0; //     RED OFF     RED OFF
         ALED = 1; //     AMBER ON    AMBER ON
         wait(2);  //     GREEN OFF   GREEN OFF
-
         //----------------------------------------------
-        RRLED = 1; //     RED OFF     RED ON
-        RLED = 0;
+        RRLED = 1;
+        RLED = 0; //     RED OFF     RED ON
         ALED = 0; //     AMBER OFF   AMBER OFF
         GLED = 1; //     GREEN ON    GREEN OFF
         wait(5);
@@ -156,26 +122,19 @@
         reset();//Reset the LEDs
     }
 }//End sequence procedure.
-
 int main()
-{
-    //start main function.
+{//start main function.
     //Main procedure, I will create a loop and initalise my variables
     /*To create my sequence I need my lights to start on the same lights everytime.
     Therefore I will create a reset which will set all of the lights off.
     I will do this by creating a separate procedure for my main procedure to point to.*/
-
-    reset();//Main points to reset procedure
-    //button.fall(&pedestrians); // This fall procedure in is the button interrupt class
-    //Switch.fall(&safe);
-    button.fall(&pedestrians);
+    reset();//Main points to reset procedure // This fall procedure in is the button interrupt class
+    Switch.fall(&safe); 
+    button.fall(&pedestrians); //& denotes the that this function is an Interrupt Service Routine
     while(1) {
         //Start of while
-
         /*infinite loop, the program will never be able to exit this loop because the condition is always TRUE.
         Now that I have set up my infinite loop I can now start the sequence procedure.*/
         sequence(unsafe);// I am calling the sequence procedure with the arguments unsafe and pedestrians.
-
     }//End of while
-    return(0); // The complier warns me that this statement is unreachable, I know. Due the infinite loop above.
 }//End main function
\ No newline at end of file