Traffic Light Timing?

ChedderCheeser

Senior Member
Hi all! I just finished my first actual project with Picaxe! It is a traffic light. I added some other code to make it more.. interesting. I also used code that wasnt NEEDED in case.. idk.. I just did. To make it more interesting. The problem is.. the timing is a bit weird... Heres the timing:

Green : 15 seconds
Yellow : 3.5 seconds
Red : 8 seconds

But.. that doesnt seem much like a REAL traffic light... Heres my code:

Code:
Init:
	setfreq m4 ;Not needed, but used anyway
	output 4 ;Not really needed, but used
	output 2 ;Not really needed, but used
	output 1 ;Not really needed, but used
	gosub flash ;Just to test the led's. NOT NEEDED AT ALL
	pause 750 ;Not needed, but used
	goto Main ;Not really needed, but used

Main:
	do
		high 4 ;Green On
		pause 15000 ;Wait 15 seconds
		low 4 ;Green Off
		pause 100 ;Wait 0.1 seconds
		
		high 2 ;Yellow off
		pause 3500 ;Wait 3.5 seconds
		low 2 ;Yellow off
		pause 100 ;Wait 0.1 seconds
		
		high 1 ;Red on
		pause 8000 ;Wait 8 seconds
		low 1 ;Red off
		pause 100 ;Wait 0.1 seconds
	loop
End

flash:
	high 4
	high 2
	high 1
	pause 250
	low 4
	low 2
	low 1
	pause 250
	high 4
	high 2
	high 1
	pause 250
	low 4
	low 2
	low 1
return
Also, I DONT want to remove the un-needed code. So.. dont mention that lol. So, what timings do you recomend? THX!!
 

eclectic

Moderator
Three questions.

1. Is this for a Picaxe 08M?

2. Simulation or on a real Picaxe?

3. In your area, what are the
real Traffic Light timings?

e
 

AndyGadget

Senior Member
This was my first picaxe project too.

Don't US traffic lights have an amber phase before going to red?
(I should remember - I was driving around there last year!)

UK ones are more interesting. They go :
Red
Red + amber
Green
Amber
Red

Don't know about your timings, but you could expand this by having the opposing set of lights (3 more LEDs) and a couple of switches simulating traffic sensors to change the timings to suit the traffic flow.

Andy.
 
Last edited:

vttom

Senior Member
What is it about the timing that you think is "weird".

After reading your code, I find myself wondering why you bother to pause 1/10 second between turning off one light and turning on the next.

Also, you might like to know that instead of doing:

high 4
high 2
high 1

you can do it on 1 line with:

high 4,2,1
 

ChedderCheeser

Senior Member
I dont know why I do what I do... I jsut felt like it lol. Also, Good idea measure my own lights... I suppose I could... but.. I dont want to go out and do that right now... As far as what is weird.. idk.. the timing just doesnt seem that realistic.. This is for an 08M and it is real. I wish I knew what our timings were so I didnt have to even have this topic! :D But.. this is more fun. :) Also, high 4,2,1 I didnt know that! THANKS!!! Anyway, I think I will leave the timing how it is. Anyway.. Thanks for the help!

EDIT:

Code:
Init:
	setfreq m4 ;Not needed, but used anyway
	output 4,2,1 ;Not really needed, but used
	gosub flash ;Just to test the led's. NOT NEEDED AT ALL
	pause 750 ;Not needed, but used
	goto Main ;Not really needed, but used

Main:
	do
		high 4 ;Green On
		pause 15000 ;Wait 15 seconds
		low 4 ;Green Off
		pause 75 ;Wait 0.1 seconds
		
		high 2 ;Yellow off
		pause 3500 ;Wait 3.5 seconds
		low 2 ;Yellow off
		pause 75 ;Wait 0.1 seconds
		
		high 1 ;Red on
		pause 8000 ;Wait 8 seconds
		low 1 ;Red off
		pause 75 ;Wait 0.1 seconds
	loop
End

flash:
	high 4,2,1
	pause 250
	low 4,2,1
	pause 250
	high 4,2,1
	pause 250
	low 4,2,1
return
 
Last edited:

ChedderCheeser

Senior Member
I suppose not. I would learn the timings. But I would just be told.. not find out myself.. So.. I guess kind of... It would probably be better if I figured it out myself.. so.. If you want to tell me thats up to you. (I assumed you would.. ) Anyway.. my answer to that is no.
 

eclectic

Moderator
I suppose not. I would learn the timings. But I would just be told.. not find out myself.. So.. I guess kind of... It would probably be better if I figured it out myself.. so.. If you want to tell me thats up to you. (I assumed you would.. ) Anyway.. my answer to that is no.
And, referring back to post #10,
an old proverb about leading a horse.

e
 

srnet

Senior Member
I dont have clue what the timings should be, but then there is a set of traffic lights a couple of mins walk from my house ......
 

manuka

Senior Member
CC et.al: Traffic light sequences make an ideal initial PICAXE project. Almost everyone is familiar with the concept, and all manner of variations (amber before green etc) can be explored. It's well worth extending things to include a pedestrian button & suitable audio-check the PICAXEd "Electronic Brain Box" layout. Stan.
 

Attachments

Last edited:

ChedderCheeser

Senior Member
You dont need to go check just for me. I can figure it out myself. I dont want to make you do all the work. Thanks for the help. (this is gonna be awkward if you werent offering to check them lol)

EDIT: manuka, Nice! That is awesome! Wonder what the sound would sound like.
 

hippy

Ex-Staff (retired)
For some reason the pedestrian crossing lights outside GEC Traffic Automation, leading to the staff bar and canteen on the other side of the road, had an instant response to pedestrian button push, about half a nanosecond on amber, and red until the PIR detected there was no one on the crossing. The most responsive traffic lights I've ever encountered :)
 

Andrew Cowan

Senior Member
For some reason the pedestrian crossing lights outside GEC Traffic Automation, leading to the staff bar and canteen on the other side of the road, had an instant response to pedestrian button push, about half a nanosecond on amber, and red until the PIR detected there was no one on the crossing. The most responsive traffic lights I've ever encountered :)
Awesome :D
 
Top