Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 1:fb4ff3d2b5d0, committed 2019-11-22
- Comitter:
 - cgoodger
 - Date:
 - Fri Nov 22 22:41:49 2019 +0000
 - Parent:
 - 0:67f1965f904d
 - Commit message:
 - Annotated Test_9 code
 
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file | 
--- a/main.cpp	Thu Nov 21 16:33:23 2019 +0000
+++ b/main.cpp	Fri Nov 22 22:41:49 2019 +0000
@@ -1,82 +1,86 @@
- //Amalgamation of Project_Test_1 and Project_Test_2_switch codes to check viability of a simple 1/2 switch light interface.
- //Expansion of Project_Test_1 protocol to include three more pins and two more traffic light circuits.
-
+//Amalgamation of Project_Test_1 and Project_Test_2_switch codes to check viability of a simple 1/2 switch light interface.
+//Expansion of Project_Test_1 protocol to include three more pins and two more traffic light circuits.
+//Project_Test_8_Switchtest2 amalgamated to provide switch command to light circuit 
+//the code checks if the value of X has changed from 0 to 1 at the end of the code turning all lights to red for 10 seconds before-
+//returning the value of X to 0 to continue the normal lights sequence. X remains 0 unless button is pressed. 
+//Normal light sequence being that the lights cycle through a red, yellow, green loop at prespecified time intervals. 
+//Lights act in opposite pairs to reduce pin number and to cimpify code. 
 
 
-#include "mbed.h"
-DigitalOut red1(p21);           //Assign digital output value of red1 to mbed pin p21
-DigitalOut yellow1(p22);        //Assign digital output value of yellow1 to mbed pin p22
-DigitalOut green1(p23);         //Assign digital output value of green1 to mbed pin p23
-DigitalOut red2(p24);           //Assign digital output value of red2 to mbed pin p24
-DigitalOut yellow2(p25);        //Assign digital output value of yellow2 to mbed pin p25
-DigitalOut green2(p27);         //Assign digital output value of green2 to mbed pin p26
-DigitalIn switchInput(p15);
+#include "mbed.h"                           //load mbed library 
+DigitalOut red1(p21);                       //Assign digital output value of red1 to mbed pin p21
+DigitalOut yellow1(p22);                    //Assign digital output value of yellow1 to mbed pin p22
+DigitalOut green1(p23);                     //Assign digital output value of green1 to mbed pin p23
+DigitalOut red2(p24);                       //Assign digital output value of red2 to mbed pin p24
+DigitalOut yellow2(p25);                    //Assign digital output value of yellow2 to mbed pin p25
+DigitalOut green2(p27);                     //Assign digital output value of green2 to mbed pin p26
+DigitalIn switchInput(p15);                 //Assign digital input value to p15 pin 
 
             
 int main() {         
     int x = 0;
-    while(1) {                  //Repeat indefinitely
-         // read the input state only once in the while loop
-        if(switchInput.read() == 0) {
-            red1 = 1;               //Turn on red1
-            red2 = 1;               //Turn on red2
-            wait(3);                //Wait 3 seconds
-            if(switchInput.read() == 1){
+    while(1) {                              //Repeat indefinitely
+                                            
+        if(switchInput.read() == 0) {       //Read the input state only once in the while loop
+            red1 = 1;                       //Turn on red1
+            red2 = 1;                       //Turn on red2
+            wait(3);                        //Wait 3 seconds
+            if(switchInput.read() == 1){    //Check condition of varibale X
                 x = 1;
                 }
-            yellow1 = 1;            //Turn on yellow1
-            wait(1);                //Wait 1 second
-            if(switchInput.read() == 1){
+            yellow1 = 1;                    //Turn on yellow1
+            wait(1);                        //Wait 1 second
+            if(switchInput.read() == 1){    //Check condition of variable X
                 x = 1;
                 }
-            red1 = 0;               //Turn off red1
-            yellow1 = 0;            //Turn off yellow1
-            green1 = 1;             //Turn on green1        
-            wait(3);                //Wait 3 seconds
-            if(switchInput.read() == 1){
+            red1 = 0;                       //Turn off red1
+            yellow1 = 0;                    //Turn off yellow1
+            green1 = 1;                     //Turn on green1        
+            wait(3);                        //Wait 3 seconds
+            if(switchInput.read() == 1){    //Check condition of variable X
                 x = 1;
                 }
-            green1 = 0;             //Turn off green1
-            yellow1 = 1;            //Turn on yellow1
-            wait(1);                //Wait 1 second
-            if(switchInput.read() == 1){
+            green1 = 0;                     //Turn off green1
+            yellow1 = 1;                    //Turn on yellow1
+            wait(1);                        //Wait 1 second
+            if(switchInput.read() == 1){    //Check condition of varible X
                 x = 1;
                 }
-            yellow1 = 0;            //Turn off yellow1
-            red1 = 1;               //Turn on red1
-            wait(3);                //Wait 3 seconds
-            if(switchInput.read() == 1){
+            yellow1 = 0;                    //Turn off yellow1
+            red1 = 1;                       //Turn on red1
+            wait(3);                        //Wait 3 seconds
+            if(switchInput.read() == 1){    //Check condition of variable X
                 x = 1;
                 }
-            yellow2 = 1;            //Turn on yellow2
-            wait(1);                //Wait 1 second
-            if(switchInput.read() == 1){
+            yellow2 = 1;                    //Turn on yellow2
+            wait(1);                        //Wait 1 second
+            if(switchInput.read() == 1){    //Check condition of variable X
                 x = 1;
                 }
-            red2 = 0;               //Turn off red2
-            yellow2=0;              //Turn off yellow2
-            green2=1;               //Turn on green2
-            wait(3);                //Wait 3 seconds
-            if(switchInput.read() == 1){
+            red2 = 0;                       //Turn off red2
+            yellow2=0;                      //Turn off yellow2
+            green2=1;                       //Turn on green2
+            wait(3);                        //Wait 3 seconds
+            if(switchInput.read() == 1){    //Check condition of variable X
                 x = 1;
                 }
-            green2 = 0;             //Turn off green2
-            yellow2=1;              //Turn on yellow2
-            wait(1);                //Wait 1 second
-            if(switchInput.read() == 1){
+            green2 = 0;                     //Turn off green2
+            yellow2=1;                      //Turn on yellow2
+            wait(1);                        //Wait 1 second
+            if(switchInput.read() == 1){    //Check condition of variable X
                 x = 1;
                 }
-            yellow2=0;              //Turn off yellow2
-            if(x == 1) {
-             red1 = 1;
-             red2 = 1;
-             yellow1 = 0;
-             yellow2 = 0;
-             green1= 0;
-             green2 = 0;
-             wait(10);
-             x = 0;
+            yellow2=0;                      //Turn off yellow2
+            if(x == 1) {                    //Check condition of varibale X
+             red1 = 1;                      //Turn on red1 
+             red2 = 1;                      //Turn on red2
+             yellow1 = 0;                   //Turn off yellow1
+             yellow2 = 0;                   //Turn off yellow2
+             green1= 0;                     //Turn off green1
+             green2 = 0;                    //Turn off green2
+             wait(10);                      //Wait 10 seconds with red1&2 in on condition 
+             x = 0;                         //Return conditoion of variable X to 0 
              }
              }
     }
-}                               //End of statement 
+}                                           //End of statement