A Wizard's staff has a knob on the end...


New Member

I recently painted up a wizard I had bought from a wargaming supplier; to make him more in keeping with the Discworld theme of my model railway layout, I gave him a hat, removed his sword, and added some glitter to both robe and hat.

I then wondered if I could replace the knob on the end of his staff with a flashing LED. I found a suitable transparent bead in my daughter's craft supplies - the hole through the middle was sufficient to take a pre-wired SMD white LED, so I removed (white metal) knob and drilled a hole down the staff (it comes out just below his hand).

The flasher could not be simpler - most of the components are power supply - the 08M2+ does all the work.

There is a video here Youtube video of wizards staff

The code is simple: The LED brightness is ramped up quickly then dies down more slowly. The flashes occur at pseudo-random intervals of up to 65 seconds.

; 20210320
; program to make the knob on the end of the wizards staff
; flash
; rev 2 shorten turn-on time

; to use the 08M2 chip

symbol dutycycle = b0
symbol offsetcounter = b1 ;offset counter for getting array contents via lookup
symbol CntDly = w4 ; a word variable for random delay
symbol ModulatorOutput = C.2

pwmout pwmdiv64, ModulatorOutput, 63, 0 ; set up PWM channel and set it off
dutycycle = 0 ; initialise duty cycle variable
CntDly = 1234 ;initialise random variable

main: ;main loop
gosub ledflash
random CntDly
pause CntDly ;pause for up to 65 sec

goto main


;subroutine for flashing the led
; the array in the lookup line is used to change the brightness of the LED
; it goes from off to half brightness, then full (255) then decays away to
; off after which the subroutine returns


for offsetcounter = 0 to 11
lookup offsetCounter, (127,255,170,113,75,50,33,22,14,10,6,0), dutycycle
pwmduty ModulatorOutput, dutyCycle
pause 40 ; pause for 40 mS
next offsetcounter

  • Like
Reactions: J G


Senior Member
That is a very nice effect you got there! I really like how the ledflash routine works. Never though of pulsing an LED like that.


Senior Member
hnorwood's Angst-Lesspork link is well worth following. Brilliant work. I hadn't visited in a few years.


New Member
Thank you! The layout hasn't been out since November 2019 as all the model railway exhibitions were cancelled at the start of the "inconvenience". However things are looking up - hope to be out soon...