Thread: Traffic light control

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    1

    Question Traffic light control

    Hi all,
    I am being asked to do a project on light traffic control on real time basis. I need to implement a C code for three intersection and display it in words on the output screen.
    I should also include the pedestrian sensor button(assign letter in keyboard). we are using QNX software on VMWare. Could you help me start with this. Some outline on how to start programming this will be useful. We are supposed to have a central controller which controls the 3 local controller intersection. Should I start with process and threads?
    If so how?

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Some more pertinent description of the project requirements could help us help you. Post the actual project description here.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    Here's something I whipped up. I'm not sure how to do the pedestrian sensor button, tho.

    Code:
    #include <stdio.h>
    #include <time.h>
    
    fiftyseconds()
    {
    	time_t start;
    	time_t current;
    	time(&start);
    	do
    	{
    		time(&current);
    	}
    	while(difftime(current,start) < 50.0);
    }
    
    twoseconds()
    {
    	time_t start;
    	time_t current;
    	time(&start);
    	do
    	{
    		time(&current);
    	}
    	while(difftime(current,start) < 2.0);
    }
    
    redlight()
    {
    	printf("X Ave. - RED; Y Blvd. - GREEN\n");
    	fiftyseconds();
    	printf("X Ave. - RED; Y Blvd. - YELLOW\n");
    	twoseconds();
    	printf("X Ave. - RED; Y Blvd. - RED\n");
    	twoseconds();
    	printf("X Ave. - GREEN; Y Blvd. - RED\n");
    	fiftyseconds();
    	printf("X Ave. - YELLOW; Y Blvd. - RED\n");
    	twoseconds();
    	printf("X Ave. - RED; Y Blvd. - RED\n");
    	twoseconds();
    }
    	
    int main()
    {
    	printf("Stoplight 1.0\n\n");
    	while(1)
    		redlight();
    	return 0;
    }
    Since I'm not an expert on stoplights, I just assumed that the green light lasts fifty seconds.
    Last edited by Babkockdood; 05-09-2010 at 01:35 PM.

  4. #4
    Registered User
    Join Date
    Aug 2010
    Posts
    1

    traffic light with LCD

    I am being asked to do a project on light traffic control. i need to use interrupt, timer and LCD and need to implement a C code for three intersection and display it in words on the output screen. i will use PIC18F4520 for this project. Timer is used to count the number of green, yellow and red color. Interrupt is applied when pedestrian walk button is pressed. Could you help me?.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Could you help me?.
    No we can't.
    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About Traffic light controller.
    By ovid in forum C++ Programming
    Replies: 4
    Last Post: 03-28-2010, 02:22 PM
  2. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 06:23 PM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. geometry won't display!?
    By psychopath in forum Game Programming
    Replies: 17
    Last Post: 09-21-2004, 10:10 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM