Sie sind auf Seite 1von 4

//Case1 3way no increment

//set outputs of traffic lights


int Bleftgreen = 24;
int Bgreen = 5;
int Byellow = 6;
int Bred = 7;
int Cgreen = 8;
int Cyellow = 9;
int Cred = 10;
int Dgreen = 11;
int Dyellow = 12;
int Dred = 13;
//set inputs of sensors
int sensor5 = 35;
int sensor7 = 37;
int sensor9 = 39;
int sensor11 = 41;
int sensor13 = 43;
int sensor15 = 45;
//set inputs for congestion
int sensor2 = 32;
int sensor4 = 34;
int sensor6 = 36;
int sensor8 = 38;
//variables
int input5= 0;
int input7= 0;
int input9= 0;
int input11= 0;
int input13= 0;
int input15= 0;
int input4 = 0;
int input6 = 0;
int input8 = 0;
void setup() {
// initialize the LEd pins as an output
pinMode(Bleftgreen, OUTPUT);
pinMode(Bgreen, OUTPUT);
pinMode(Byellow, OUTPUT);
pinMode(Bred, OUTPUT);
pinMode(Cgreen, OUTPUT);
pinMode(Cyellow, OUTPUT);
pinMode(Cred, OUTPUT);
pinMode(Dgreen, OUTPUT);
pinMode(Dyellow, OUTPUT);
pinMode(Dred, OUTPUT);
//initialize the
pinMode(sensor5,
pinMode(sensor7,
pinMode(sensor9,

sensor pins as an input


INPUT);
INPUT);
INPUT);

pinMode(sensor11, INPUT);
pinMode(sensor13, INPUT);
pinMode(sensor15, INPUT);
pinMode(sensor4, INPUT);
pinMode(sensor6, INPUT);
pinMode(sensor8, INPUT);
}
void loop () {
input5 = digitalRead(sensor5);
input7 = digitalRead(sensor7);
input9 = digitalRead(sensor9);
input11 = digitalRead(sensor11);
input13 = digitalRead(sensor13);
input15 = digitalRead(sensor15);
input4 = digitalRead(sensor4);
input6 = digitalRead(sensor6);
input8 = digitalRead(sensor8);
//main code
if(input5 == HIGH && input7 == HIGH && input9 == LOW && input11 == LOW && input
13 == LOW && input15 == LOW){ //Traffic light B caseone
if(input8 == LOW && input6 == LOW){
five();
}else if(input8 == HIGH && input6 == HIGH){
four();
}else if(input8 == LOW && input6 == HIGH){
one();
}else{
six();
}
}else if(input5 == LOW && input7 == LOW && input9 == HIGH && input11 == HIGH &&
input13 == LOW && input15 == LOW){ //TC casetwo
if(input8 == LOW){
two();
}else{
six();
}
}else if(input5 == LOW && input7 == LOW && input9 == LOW && input11 == LOW && i
nput13 == HIGH && input15 == LOW){ //TD casethree
if(input4 == LOW){
one();
}else{
if(input8 == LOW){
three();
}else{
six();
}
}
}else if(input5 == HIGH && input7 == HIGH && input9 == LOW && input11 == LOW &&
input13 == HIGH && input15 == HIGH){ //TB & TD casefour
if(input8 == LOW && input4 == LOW){
one();
}else{
six();
if(input8 == LOW && input4 == HIGH){
five();
}else{

four();
}
}
}else if(input5 == HIGH && input7 == HIGH && input9 == HIGH && input11 == HIGH
&& input13 == LOW && input15 == LOW){ //TB & TC casefive
if((input8 == LOW && input6 == LOW) || input8 == LOW){
three();
}else{
four();
}
}else if(input5 == LOW && input7 == LOW && input9 == HIGH && input11 == HIGH &&
input13 == HIGH && input15 == HIGH){ //TC & TD casesix
if(input8 == LOW && input4 == LOW){
one();
two();
}else{
if(input8 == LOW && input4 == HIGH){
five();
}else{
four();
}
}
}else if(input5 == HIGH && input7 == HIGH && input9 == HIGH && input11 == HIGH
&& input13 == HIGH && input15 == HIGH){ //TB, TC & TD caseseven
seven();
}else{ //NONE caselast
last();
}
}
void one(){
digitalWrite(Bgreen, HIGH);
digitalWrite(Cred, HIGH);
digitalWrite(Dgreen, HIGH);
delay(5000);
digitalWrite(Bgreen, LOW);
digitalWrite(Cred, LOW);
digitalWrite(Dgreen, LOW);
}
void two(){
digitalWrite(Bred, HIGH);
digitalWrite(Cgreen, HIGH);
digitalWrite(Dred, HIGH);
delay(5000);
digitalWrite(Bred, LOW);
digitalWrite(Cgreen, LOW);
digitalWrite(Dred, LOW);
}
void three(){
digitalWrite(Bgreen, HIGH);
digitalWrite(Cgreen, HIGH);
digitalWrite(Dred, HIGH);
delay(5000);
digitalWrite(Bgreen, LOW);
digitalWrite(Cgreen, LOW);
digitalWrite(Dred, LOW);
}
void four(){
digitalWrite(Bred, HIGH);

digitalWrite(Cred, HIGH);
digitalWrite(Dgreen, HIGH);
delay(5000);
digitalWrite(Bred, LOW);
digitalWrite(Cred, LOW);
digitalWrite(Dgreen, LOW);
}
void five(){
digitalWrite(Bleftgreen, HIGH);
digitalWrite(Bgreen, HIGH);
digitalWrite(Cred, HIGH);
digitalWrite(Dred, HIGH);
delay(5000);
digitalWrite(Bleftgreen, LOW);
digitalWrite(Bgreen, LOW);
digitalWrite(Cred, LOW);
digitalWrite(Dred, LOW);
}
void six(){
digitalWrite(Bleftgreen, HIGH);
digitalWrite(Cred, HIGH);
digitalWrite(Dred, HIGH);
delay(5000);
digitalWrite(Bleftgreen, LOW);
digitalWrite(Cred, LOW);
digitalWrite(Dred, LOW);
}
void seven(){
digitalWrite (Bred, HIGH);
digitalWrite (Cred, HIGH);
digitalWrite (Dred, HIGH);
delay(5000);
digitalWrite (Bred, LOW);
digitalWrite (Cred, LOW);
digitalWrite (Dred, LOW);
}
void last(){
//intial blinking
digitalWrite(Byellow, HIGH);
digitalWrite(Cyellow, HIGH);
digitalWrite(Dyellow, HIGH);
delay(1000);
digitalWrite(Byellow, LOW);
digitalWrite(Cyellow, LOW);
digitalWrite(Dyellow, LOW);
delay(1000);
}

Das könnte Ihnen auch gefallen