Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include <mbed.h>
//Setup the LED1 pin to be a digial output called ledOne
DigitalOut carRed(LED3); //Driver Green
DigitalOut carAmber(LED2); //Driver Amber
DigitalOut carGreen(LED1); //Crossing Green
DigitalOut pedRed(D15); //Crossing Red (External LED, modify for online version)
DigitalOut pedGreen(D14);
InterruptIn button(BUTTON1);
int buttonState =0;
int programState = 0;
void handler(){
//only Respond to button press if we are in state 0
if (programState==0){
programState+=1;
}
}
void defaultState(){
carRed = 0;
carAmber = 0;
carGreen = 1;
pedRed = 1;
pedGreen = 0;
wait(5);
}
void stopping(){
//We only need to update the car
carRed = 1;
carAmber =1;
carGreen = 0;
wait(2); // Wait for some arbatory length of time
programState+=1;
}
void crossing(){
carRed = 1;
carAmber = 0;
pedRed = 0;
pedGreen = 1;
wait(5); // Wait for some arbatory length of time
programState+=1;
}
void endCrossing(){
carRed = 0;
for (int i=0; i<10; i++){
pedGreen = 1;
carAmber = 1;
wait(0.5);
pedGreen = 0;
carAmber = 0;
wait(0.5);
}
programState=0;
}
int main() {
// put your setup code here, to run once:
printf("Initialising\n");
button.rise(&handler);
while(1) {
//Read the Button and change the state
//if (button){
// buttonstate = !buttonstate;
//}
printf("Tick...%d\n", programState);
switch( programState){
case 1:
stopping();
break;
case 2:
crossing();
break;
case 3:
endCrossing();
break;
default:
defaultState();
}
wait(1);
}
}