Make some programmable crossing signal lights

Cut-and-paste programs for six different styles of lighting
RELATED TOPICS: CONTROL AND ELECTRICAL
In the August 2014 issue, David Bodnar shows us how to program a Picaxe to make realistic signal lights. Cut-and-paste the code here for six different projects.

Program 1: A simple crossing signal

#TERMINAL 4800 'set the speed of the terminal

SYMBOL LED1 = b.2 'pin 11
SYMBOL LED2 = b.4 'pin 9

SERTXD (13,10,"Crossing Signal - d. bodnar 5-20-2013")

Initialize:
HIGH LED1 ' LED1 ON
LOW LED2 ' LED2 OFF

Start: ' just a LABEL

TOGGLE LED1 ' if LED1 is on turn it off, if off turn on
TOGGLE LED2 ' same for LED2
PAUSE 500 ' PAUSE for 1/2 second

GOTO Start: 'Do it again

Program 2: A simple crossing signal with timer

#TERMINAL 4800

SYMBOL LED1 = b.2 'pin 11
SYMBOL LED2 = b.4 'pin 9

SERTXD (13,10,"Timed Crossing Signal - d. bodnar 5-20-2013",13,10)
Initialize:
HIGH LED1 ' LED1 ON
LOW LED2 ' LED2 OFF

FOR B1 = 1 TO 20 'repeat things between here and NEXT B1 20 times
SERTXD ("B1 = ",#b1,13,10) ' display value of B1 on terminal
TOGGLE LED1
TOGGLE LED2
PAUSE 500
NEXT B1 'go back and get the NEXT B1 until it equals 20
SERTXD ("Pausing for 10 seconds",13,10)
LOW LED1 'LED1 off
LOW LED2 'LED2 off
FOR B1 = 1 TO 10
SERTXD ("PAUSE = ",#b1,13,10) ' show the seconds that have passed
PAUSE 1000 'PAUSE for 1 second
NEXT B1
GOTO Initialize: 'do it again

Program 3: Triggering the crossing

#TERMINAL 4800
SYMBOL LED1 = b.2 'pin 11
SYMBOL LED2 = b.4 'pin 9
SYMBOL Trigger1 = pinc.4 'pin 3

SERTXD (13,10,"Triggered Crossing Signal - d. bodnar 5-20-2013",13,10)

StayHere:
SERTXD ("No Trigger Seen",13,10)
IF Trigger1 = 1 THEN StayHere: 'no button - keep looking

Initialize:
HIGH LED1 ' LED1 ON
LOW LED2 ' LED2 OFF

FOR B1 = 1 TO 30
SERTXD ("B1 = ",#b1,13,10) ' B1 value to terminal
TOGGLE LED1
TOGGLE LED2
PAUSE 500
NEXT B1 'get NEXT B1 until it equals 30

SERTXD ("Done Flashing",13,10)
LOW LED1
LOW LED2

GOTO StayHere:

Program 4: Triggering from either direction and stopping when passed

#TERMINAL 4800

SYMBOL LED1 = b.2 'pin 11
SYMBOL LED2 = b.4 'pin 9
SYMBOL Trigger2 = pinc.3 'pin 4
SYMBOL Trigger1 = pinc.4 'pin 3

SERTXD (13,10,"Two Trigger Crossing Lights - d. bodnar 5-30-2013")

PauseBeforeStart: 'prevents detecting slow button push
LOW LED1
LOW LED2
PAUSE 1000

CheckButtons:
SERTXD ("No Trigger Seen",13,10)
b1=0:b2=0 'clear variables
IF Trigger1 = 1 AND Trigger2 = 1 THEN CheckButtons ' no button hit
if Trigger1 = 0 THEN
SERTXD ("Trigger 1 hit first",13,10)
b1=1 'save which button hit first
GOTO Flash 'skip ahead and start blinking
ENDIF
SERTXD ("Trigger 2 hit first",13,10)
b2=1 'save which button hit first
Flash:
HIGH LED1
LOW LED2
FlashAgain:
FOR w3= 1 TO 100 'check for button before changing lights
IF b2=1 AND Trigger1=0 THEN PauseBeforeStart
IF b1=1 AND Trigger2=0 THEN PauseBeforeStart
NEXT w3
SERTXD ("toggling!",13,10)
TOGGLE LED1:TOGGLE LED2
GOTO FlashAgain:

Program 5: Setting operation time with a potentiometer

#TERMINAL 4800

SYMBOL LED1 = b.2 'pin 11
SYMBOL LED2 = b.4 'pin 9
SYMBOL Pot1 = pinb.1 'pin 12
SYMBOL PotValue = b2
SYMBOL Dlay =w3

SERTXD (13,10,"Simple Crossing Signal - d. bodnar 5-30-2012") ' show name on terminal

Initialize: ' do this only once
High LED1 ' LED1 is ON
Low LED2 ' LED2 is OFF

Start: ' LABEL so the GOTO knows where to go!
READADC b.1, PotValue
SERTXD ("pot=",#PotValue,13,10)
TOGGLE LED1 ' if LED1 is on turn it off, if off turn on
TOGGLE LED2 ' same for LED2
Dlay=PotValue*2
PAUSE Dlay ' pause time based on pot reading
GOTO start: ' go back to Start and do it again

Program 6: Two triggers with a pot to vary speed of flashing

#TERMINAL 4800

SYMBOL LED1 = b.2 'pin 11
SYMBOL LED2 = b.4 'pin 9
SYMBOL Trigger2 = pinc.3 'pin 4
SYMBOL Trigger1 = pinc.4 'pin 3
SYMBOL Pot1 = pinb.1 'pin 12
SYMBOL PotValue = b3

SERTXD (13,10,"Two Trigger Crossing Lights with POT - d. bodnar 5-20-2013")

PauseBeforeStart: 'prevents detecting slow button push
LOW LED1 ‘turn off LED 1
LOW LED2 ‘turn off LED 2
PAUSE 1000 'PAUSE 1 second

CheckButtons:
SERTXD ("No Trigger Seen",13,10)
b1=0:b2=0 'clear variables that store which button came first
IF Trigger1 = 1 AND Trigger2 = 1 THEN CheckButtons ' no button hit
IF Trigger1 = 0 THEN
SERTXD ("Trigger 1 hit first",13,10)
b1=1 'save which button hit first
GOTO flash 'skip ahead and start blinking
ENDIF
SERTXD ("Trigger 2 hit first",13,10)
b2=1 'save which button hit first
Flash:
HIGH LED1 'LED 1 on
LOW LED2 'LED 2 off
FlashAgain:
READADC b.1, PotValue 'read potentiometer value
FOR w3= 1 TO PotValue 'check for button before changing lights
IF b2=1 AND Trigger1=0 THEN PauseBeforeStart
IF b1=1 AND Trigger2=0 THEN PauseBeforeStart
NEXT w3
SERTXD ("toggling! Pot=",#PotValue,13,10)
TOGGLE LED1:TOGGLE LED2 ‘switch lights
GOTO FlashAgain: 'continue checking buttons

JOIN THE DISCUSSION

Read and share your comments on this article
COMMENT ON THIS ARTICLE

Want to leave a comment?

Only registered members of GardenRailways.com are allowed to leave comments. Registration is FREE and only takes a couple minutes.

Login or Register now.
0
How to Make Signs

How to Make Signs

Custom stickers, dry transfers, decals, and more!

FREE EMAIL NEWSLETTER

Get the Garden Railways newsletter delivered to your inbox twice a month

By signing up you may also receive occasional reader surveys and special offers from Garden Railways magazine. Please view our privacy policy