This is it. Enjoy. Sorry about formatting. Long story.
'************************************************* ***************
'* Name : Randomize 20 LEDs.BAS *
'* Author : Greg Browne *
'* Notice : Copyright (c) 2011 Not a chance *
'* : All Rights Reserved *
'* Date : 08/30/2011 *
'* Version : 1.0 *
'* Notes : 12f683 w/ nap to conserve power and various *
'* : lighting sequences *
'************************************************* ***************
' needs to be streamlined for cleaner reading
clear
define osc 4
' ------------------------------------turn off some stuff to save a little power
@ device mclr_off 'start button is connected here
@ device bod_off
@ device fcmen_off
@ device ieso_off
@ device intrc_osc_noclkout
@ device pwrt_on
@ device protect_off
ansel = 0
cmcon0 = 7
adcon0 = 0
' --------------------------------------------------------------- some variables
delay2 var word
myword var word
delay var byte
mybyte var byte
previous_random var byte
gpiostate var byte
tristate var byte
i var byte
j var byte
k var byte
l var byte
' ------------------------------------------------------------------ some values
delay = 50
delay2 = 500
'------------------------------------------------------------finally the program
starthere:
if gpio.3 = 1 then goto main
nap 4 'naps for 288 milliseconds
goto starthere
'--------------------------------------------flash them all to make it look cool
main:
for i = 1 to 20
random myword
mybyte = (myword//20)
if previous_random = mybyte then goto main
gosub high_led
pause delay
gpio = %000000
pause delay
previous_random = mybyte
next i
'---------------------------------------------------------------- first 13 boxes
mybyte = 0' start LEDs in sequence
for mybyte = 0 to 12
gosub high_led
pause delay2*2
gpio=%000000
pause delay
next mybyte
'---------------------------------------------------------- four stars real fast
mybyte = 13' beginning of stars
for j = 1 to 4
for mybyte = 13 to 16
gosub high_led
pause delay2/5
gpio=%000000
pause delay
next mybyte
next j
'---------------------------------------- four stars with another blinking twice
mybyte = 13' beginning of stars
for mybyte = 13 to 17 ' with the HUD glass this time
gosub high_led
pause delay2
gpio=%000000
pause delay
next mybyte
' ---------------------------------------blinks these lights k number of times
mybyte = 17
for k= 1 to 3
gosub high_led
pause 500
gpio = 0
pause 100
next k
'-----------------------------------now for the flag and name//take this out ???
' mybyte = 18' show them off a little
'for mybyte = 18 to 19
' gosub high_led
' pause delay2
' gpio=%000000
' pause delay
'next mybyte
'----------------------------------------light american flag first then name tag
trisio = %001111
gpio = 0
for l = 0 to 255 step 5' led18 gpio.4
pwm gpio.4,l,10' light number 18, l intensity step, 10 usec
next l
for l = 255 to 0 step -5
pwm gpio.4,l,10
next l
trisio = %001111
for l = 0 to 255 step 5 'led 19 is gpio.5
pwm gpio.5,l,10' light number 19, l intensity step, 10 usec
next l
for l = 255 to 0 step -5
pwm gpio.5,l,10
next l
'----------------------------------------------------------------turn it all off
gpio = 0
trisio = %111111
' -----------------------------------------------------------send it back to nap
goto starthere
high_led:
lookup mybyte,[%000001,%000010,%000001,%000100,%000001,%010000,%0 00001,%100000,%000010,%000100,%000010,%010000,%000 010,%100000,%000100,%010000,%000100,%100000,%01000 0,%100000],gpiostate
gpio = gpiostate
lookup mybyte,[%111100,%111100,%111010,%111010,%101110,%101110,%0 11110,%011110,%111001,%111001,%101101,%101101,%011 101,%011101,%101011,%101011,%011011,%011011,%00111 1,%001111],tristate
trisio = tristate
return
end
Bookmarks