'
' USB Xmas LED flasher
' Get command from the PC, flash the leds and play tunes
'
'
' Commands:
' 0 - All LEDs off
' 1 - Play Jinge Bells
' 2 - Play Silent Night
' 3 - Play Rudolph the Red Nosed Reindeer
' 4 - Play all tunes
' 5 - Flash the LEDs slow
' 6 - Flash the LEDs fast
' 7 - Animate LEDs slow
' 8 - Animate LEDs fast
' Define the output pins
Symbol LED = 4
Symbol PIEZO = 2
Symbol DISPLAY = 0
Symbol SLOW = 800
Symbol FAST = 400
' Define some extra symbols
Symbol CMD = b0
Symbol NEWCMD = b1
' Initialize
' Make a small pause to let everything settle down
pause 3000
let NEWCMD = 0
high DISPLAY
' Set the interrupt to receive commands from the keyboard
setint %00000000, %00001000
' Move to a standard action
goto animate_leds_slow
main:
' Check the command we received
' Reset the NEWCMD flag
let NEWCMD = 0
high DISPLAY
if CMD > 9 then goto animate_leds_slow
branch CMD, (turn_off, play_tune_1, play_tune_2, play_tune_3, play_all_tunes, flash_leds_slow, flash_leds_fast, animate_leds_slow, animate_leds_fast)
goto turn_off
interrupt:
' Get a new command from the PC
' Display the command prompt after a brief delay
pause 100
serout 1, t2400, ("*?")
' SerIn to get the command
serin 3, t2400, #CMD
' Respond with the command
serout 1, t2400, ("!", #CMD)
' Set the interrupt again
'pause 100
setint %00000000, %00001000
' Set the NEWCMD to1
let NEWCMD = 1
' Return to main loop
return
'
' Play tunes part
'
play_tune_1:
' Play the Jingle Bells tune
play 1, 2
return
play_tune_2:
' Play Silent Night tune
play 2, 2
return
play_tune_3:
' Play the Rudolph tune
play 3, 2
return
play_all_tunes:
' Play all tunes in sequence (CMD 4)
' Call the first tune
gosub play_tune_1
pause 1000
' Call the second tune
gosub play_tune_2
pause 1000
' Call the third tune
gosub play_tune_3
return
'
' Flash LEDs part
'
flash_leds_slow:
' Flash the LEDs while animating them slowly
' Pulse the LED pin
gosub pulse_led
' Set the DISPLAY pin high and wait
high DISPLAY
pause SLOW
low DISPLAY
pause SLOW
if NEWCMD = 1 then
' We had a new command - move control to main subrouting to execute the new command
goto main
endif
goto flash_leds_slow
flash_leds_fast:
' Flash the LEDs while animating them slowly
' Pulse the LED pin
gosub pulse_led
' Set the DISPLAY pin high and wait
high DISPLAY
pause FAST
low DISPLAY
pause FAST
if NEWCMD = 1 then
' We had a new command - move control to main subrouting to execute the new command
goto main
endif
goto flash_leds_fast
animate_leds_slow:
' Animate the LEDs slowly - this requires to send pulses through pin4
' Send a pulse
gosub pulse_led
' Check f we got interrupted for a new command
if NEWCMD = 1 then
' We had a new command - move control to main subrouting to execute the new command
goto main
else
' do the loop again
pause SLOW
goto animate_leds_slow
endif
animate_leds_fast:
' Animate the LEDs fast - this requires to send pulses through pin4
' Send a pulse
gosub pulse_led
' Check f we got interrupted for a new command
if NEWCMD = 1 then
' We had a new command - move control to main subrouting to execute the new command
goto main
else
' do the loop again
pause FAST
goto animate_leds_fast
endif
pulse_led:
' Send a pulse through the LED port
high LED
pause 20
low LED
return
turn_off:
' Turn the LEDs off until a new command is in
low DISPLAY
off_loop:
' loop
pause 1000
if NEWCMD = 1 then
' We had a new command - move control to main subrouting to execute the new command
goto main
endif
goto off_loop