top of page
Search

Traffic Lights Demonstration

  • Writer: Christopher Pereyra
    Christopher Pereyra
  • May 27, 2021
  • 1 min read

Traffic Lights


On the motherboard I attached 6 LEDS. 3 Represented the lights on one side of the street, 3 represented the lights on the other side of the street. I attached resistors and wires to power the lights. I wrote code which started a sequence exactly like a stop light. Each of the different light colors had a different duration they would last.


Code


#include "simpletools.h" // Include simple tools


int main() // Main function

{

char const button = 6;

while(1)

{

if(input(button)){

printf("%c%cbutton is pressed \n",CLREOL,HOME); //terminal will indicate whether the button is pressed.

for(int i =0; i<1; i=i+1){

//......North + South Street Light................................................. .. . ...

// Green Light (N/S) & Red Light (W/E)

high(5); //(Red Light from E/W will be on for 4 seconds, until N/S light turns Red (15)

pause(750);// Short transition from red, to green

low(15);

high(13); // (ON)

pause(3000); // (Pause program execution for 1 sec)

low(13); // (OFF)

// Yellow Light

high(14);

pause(1000);

low(14) ;

//........East + West Street Light....................

// Green (W/E) & Red Light (N/S)

high(15); // Red light (N/S) on

pause(750);//Short transition from red, to green

low(5); // Red light (W/E) off

high(3); // Green light (W/E) on

pause(3000);

low(3);

// Yellow Light (W/E)

high(4);

pause(1000);

low(4);

}

}

else

{

printf("%c%cButton is not pressed \n",CLREOL,HOME);

high(13);

low(15);

high(5);

}

}

}




 
 
 

Komentar


Post: Blog2_Post

©2019 by Christopher Pereyra. Proudly created with Wix.com

bottom of page