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
main.cpp
- Committer:
- jfair
- Date:
- 2019-10-29
- Revision:
- 0:47a0c4ac5a0f
- Child:
- 1:7b7576c83317
File content as of revision 0:47a0c4ac5a0f:
#include "mbed.h"
DigitalOut ga(p23); //defines the green light for first seqeunce
DigitalOut ya(p22); //defines the yellow light for first sequence
DigitalOut ra(p21); //defines the red light for first sequence
DigitalOut gb(p27); //defines green light for second sequence
DigitalOut yb(p25); //defines yellow light for second sequence
DigitalOut rb(p24); //defines red light for second sequence
DigitalIn button(p18); //defines the switch as a digital input
bool cross;
void crossing() {
ra = 1;//simultainiously turns on red lights to allow crossing
rb = 1;
ga = 1;//remove later for testing
wait (1);//r
ga = 0;//r
wait (1);//r
ga = 1;//r
wait (1);//r
ga = 1;//r
cross = 1;//sets value of crossing request to false to prevent looping
wait (1);//remove later for testing
}
//no wait should be required here as the normal lights function begins with a red light, this also minimises disruption
void lightsa() { //creates the function for the first lights sequence
ra = 1; //turns on red light at same time
wait(3); //waits ten seconds
ya = 1; //turns the yellow light on
wait(1); //waits two seconds
ra = 0; //turns off red light
ya = 0; //turns off yellow light at same time
ga = 1; //turns on green light at the same time
wait (3); //waits fourteen seconds
ga = 0; // turns off green
ya = 1; // turns on yellow light at same time
wait (1); //waits three seconds before repeating
ya = 0; //turns off yellow light
}
void lightsb() { //creates the function for the second lights sequence
rb = 1; //turns on red light at same time
wait(10); //waits ten seconds
yb = 1; //turns the yellow light on
wait(2); //waits two seconds
rb = 0; //turns off red light
yb = 0; //turns off yellow light at same time
gb = 1; //turns on green light at the same time
wait (14); //waits fourteen seconds
gb = 0; // turns off green
yb = 1; // turns on yellow light at same time
wait (3); //waits three
yb = 0; //turns off yellow light
}
int main() {
while(1) { //repeats indefinitely
if (button.read()) {
cross = 0;
}
if (cross == 1) {
rb = 1; //keeps red light from second sequence on during sequence one
lightsa(); //calls the function for the first lights sequence
ra = 1; //keeps red light for sequence one on during sequence two
}
else {
crossing ();
}
}
}