Build a lighthouse beacon or Mars light

Cut and paste code for a Mars light and more

RELATED TOPICS: CONTROL AND ELECTRICAL
picaxe
The flashing lighthouse beacon is controlled by a inexpensive microcontroller called a Picaxe.
David Bodnar
In the April 2013 issue, David Bodnar explains how to use and program a Picaxe to make a lighthouse beacon or Mars light. Cut and paste the code here to save time on your project!

Program 1

#Picaxe 08M2 'tell the program which chip we have
Top: 'label to indicated the top of the program
HIGH 2 'light the LED on output #2, pin 5
PAUSE 500 'pause for 1/2 second (500/1000 sec)
LOW 2 'turn off the LED
PAUSE 500 'pause again
GOTO Top: 'go back to the label "Top:"
Click on the "Syntax" button at the top of the editor.

If you have entered the program correctly you will get a report of success and the number of bytes of memory that were used and those remaining.

Lighthouse-beacon program

#NO_DATA 'speeds up programming
#Picaxe 08M2 'identify the chip
SETFREQ m32 'speed it up to 32 MHz
SYMBOL Loopie = b2 'label variable b2 as Loopie
SYMBOL Brightness = b1 'label b1 as Brightness
SYMBOL Dlay = 150 'set constant Dlay to 150
Start:
For Loopie = 0 to 100 step 1 '100 steps from off to bright
brightness=255-loopie
pwmout c.2, brightness, loopie 'use PWM to brighten the LED
pause Dlay 'pause a bit
next loopie 'get the next item in for/next
pwmout c.2, 255,1023:pause 1000 'flash to full bright briefly
for loopie = 100 to 0 step -1 'repeat above backwards
brightness=255-loopie
pwmout c.2, brightness,loopie
pause Dlay
next loopie
pause 2000 'pause a bit with LED off
goto start 'do it again!

Mars light program

#NO_DATA 'speeds up programming
#Picaxe 08M2 'identify the chip
SETFREQ m32 'speed it up to 32 MHz
SYMBOL Loopie = b2 'label variable b2 as Loopie
SYMBOL Brightness = b1 'label b1 as Brightness
SYMBOL Dlay = 2 'set constant Dlay to 2
Start:
Gosub ShortFlash 'do the shorter flash routine
Gosub LongFlash 'do the longer flash routine
GOTO Start: 'repeat
ShortFlash: 'a label
For Loopie = 0 to 100 step 1 '100 steps from off to bright
brightness=255-loopie
pwmout c.2, brightness, loopie 'light the LED
pause Dlay
next loopie
for loopie = 100 to 0 step -1 'repeat above backwards
brightness=255-loopie
pwmout c.2, brightness,loopie
sertxd (#loopie, " ")
pause Dlay
next loopie
return 'return to the point where the routine was called
LongFlash: 'do the longer flash
For Loopie = 0 to 255 step 1 '255 steps from off to bright
brightness=255-loopie
pwmout c.2, brightness, loopie
pause Dlay
next loopie
for loopie = 255 to 0 step -1 'repeat above backwards
brightness=255-loopie
pwmout c.2, brightness,loopie
pause Dlay
next loopie
return

Morse-code program

SYMBOL Deelay = 500
SYMBOL dittime = b4
SYMBOL LED = c.2 'Pin 5
dittime = 100
EEPROM 0, (" welcome de n3enm pittsburgh !") 'message must be lower case - numbers OK - ! to end
Start:
for b1=0 to 255
read b1,b2
sertxd (b2," ")',#b2)
if b2="!" then SkipOut: 'finished with text - stop sending
if b2>= "0" and b2<="9" then 'if it is a numeral adjust
b2=b2 -48+26
goto SkipHere:
endif
if b2=" " then 'if a space adjust
sertxd ("space",13,10)
pause Deelay' space to pause between words
goto Skipover:
endif
b2=b2-97 'decrease ASCII value for "a" to 0, "b" to 1, etc
SkipHere:
on b2 gosub aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz,n0,n1,n2,n3,n4,n5,n6,n7,n8,n9
Skipover:
pause Deelay
next b1
SkipOut:
goto Start:
aa:gosub dit:gosub dah:return
bb:gosub dah:gosub dit:gosub dit:gosub dit:return
cc:gosub dah:gosub dit:gosub dah:gosub dit:return
dd:gosub dah:gosub dit:gosub dit:return
ee:gosub dit:return
ff:gosub dit:gosub dit:gosub dah:gosub dit:return
gg:gosub dah:gosub dah:gosub dit:return
hh:gosub dit:gosub dit:gosub dit:gosub dit:return
ii:gosub dit:gosub dit:return
jj:gosub dit:gosub dah:gosub dah:gosub dah:return
kk:gosub dah:gosub dit:gosub dah:return
ll:gosub dit:gosub dah:gosub dit:gosub dit:return
mm:gosub dah:gosub dah:return
nn:gosub dah:gosub dit:return
oo:gosub dah:gosub dah:gosub dah:return
pp:gosub dit:gosub dah:gosub dah:gosub dit:return
qq:gosub dah:gosub dah:gosub dit:gosub dah:return
rr:gosub dit:gosub dah:gosub dit:return
ss:gosub dit:gosub dit:gosub dit:return
tt:gosub dah:return
uu:gosub dit:gosub dit:gosub dah:return
vv:gosub dit:gosub dit:gosub dit:gosub dah:return
ww:gosub dit:gosub dah:gosub dah:return
xx:gosub dah:gosub dit:gosub dit:gosub dah:return
yy:gosub dah:gosub dit:gosub dah:gosub dah:return
zz:gosub dah:gosub dah:gosub dit:gosub dit:return
n0:gosub dah:gosub dah:gosub dah:gosub dah:gosub dah:return
n1:gosub dit:gosub dah:gosub dah:gosub dah:gosub dah:return
n2:gosub dit:gosub dit:gosub dah:gosub dah:gosub dah:return
n3:gosub dit:gosub dit:gosub dit:gosub dah:gosub dah:return
n4:gosub dit:gosub dit:gosub dit:gosub dit:gosub dah:return
n5:gosub dit:gosub dit:gosub dit:gosub dit:gosub dit:return
n6:gosub dah:gosub dit:gosub dit:gosub dit:gosub dit:return
n7:gosub dah:gosub dah:gosub dit:gosub dit:gosub dit:return
n8:gosub dah:gosub dah:gosub dah:gosub dit:gosub dit:return
n9:gosub dah:gosub dah:gosub dah:gosub dah:gosub dit:return
dit:
sertxd (".")
high LED
pause dittime
low LED
pause dittime
return
dah:
sertxd ("-")
high LED
pause dittime :pause dittime:pause dittime
low LED
pause dittime
return

Additional resources

The author's website: http://trainelectronics.com

The Picaxe website: http://picaxe.com

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
DCC for Large Scale

DCC for Large Scale

Our four-part beginner's guide.

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