'This is a 5 mode vu lighting program intended for psp drive bays
'writen by christian doran
'22/04/2010
setfreq 8 'seting clock speed to 8Hzs
low portc 1 'seting the led's ground
b6 = 0 'sets the sleep timer to zero
Main:
for b5 = 7 to 0 step -1 'This is an opening intro, leds wipe in then out
high b5
pause 100
next b5
pause 250
for b5 = 7 to 0 step -1
low b5
pause 100
next b5
pause 250
b10 = 0 'Resets the mode counter
do
pwmout 2, OFF ' Reseting the pwm outputs
pwmout 1, OFF
low portc 1 'seting the led grnd back to 0v
if pin6 = 0 then mode_check 'check for mode input
loop while pin6 = 1 'go back to start if no input
mode_check:
pwmout 1,off 'this section checks the mode counter and switches to the
pwmout 2,off 'corect mode.
low 0,1,2,3,4,5,6,7 'ensuring all leds are off
low portc 2
inc b10
if b10 = 1 then mode1
if b10 = 2 then mode2
if b10 = 3 then mode3
if b10 = 4 then mode4
if b10 = 5 then mode5
if b10 = 6 then main
Mode1:
for b5 = 7 to 0 step -1 'mode change animation
high b5
pause 100
next b5
pause 250
for b5 = 7 to 0 step -1
low b5
pause 100
next b5
pause 250 'leds are lit to show mode nuber entered
high 7
pause 250
low 7
pause 500
High portc 2 'this mode is ambient lighting only
do
if pin6 = 0 then mode_check
loop while pin6 = 1
mode2:
for b5 = 7 to 0 step -1
high b5
pause 100
next b5
pause 250
for b5 = 7 to 0 step -1
low b5
pause 100
next b5
pause 250 'this mode enter the VU program with ambient lighting on
High portc 2
pause 500
High 7,6
pause 250
low 7,6
pause 500
goto VU
mode3:
for b5 = 7 to 0 step -1
high b5
pause 100
next b5
pause 250
for b5 = 7 to 0 step -1
low b5
pause 100
next b5
pause 250 'this mode enters the VU program without ambient lighting
High 7,6,5
pause 250
low 7,6,5
pause 500
goto VU
mode4:
for b5 = 7 to 0 step -1 'this mode enters the VU with toplevel animation
high b5
pause 100
next b5
pause 250
for b5 = 7 to 0 step -1
low b5
pause 100
next b5
pause 250
High 7,6,5,4
pause 250
low 7,6,5,4
pause 500
goto Top_LevelVU
mode5:
for b5 = 7 to 0 step -1 'this mode enters the VU with toplevel animation with ambient lighting
high b5
pause 100
next b5
pause 250
for b5 = 7 to 0 step -1
low b5
pause 100
next b5
pause 250
high portc 2
pause 500
High 7,6,5,4,3
pause 250
low 7,6,5,4,3
pause 500
goto Top_LevelVU
VU:
readadc 1,b0 'reading volume input from the adc
b2 = 7 'seting the led number to 7
for b1 = 0 to 105 step 15 'seting the volume levels to check againsed the adc reading
if b0=0 then inc b6 'if the volume is zero add one to the sleep timer
end if
if b6 = 50 then goto shows_over 'if the sleep counter has reached 1000 go into sleep mode
if b0 > b1 then high b2 else goto readagain
if pin6 = 0 then goto mode_check 'if the adc reading is higher than the
endif 'curent level check then light led if not
dec b2 'move to another reading
b6 = 0 'reset the sleep counter as there is volume
next b1 'move to check the next volume level
readagain:
readadc 1,b3 'take a new volume reading
if b3 < b0 then goto lights_out
if pin6 = 0 then goto mode_check 'if the volume has lowered move to lights out program
goto VU 'move to take a new reading
lights_out:
b3 = 0 'seting new led number
for b1 = 120 to 15 step -15 'levels to check the adc volume againsed
if b0 =< b1 then low b3 else goto VU 'if the volume is the same as
if pin6 = 0 then goto mode_check 'or lower than the level check, then turn out the led.
end if 'checking to for input
inc b3
next b1 'goto next led
goto VU 'take new reading
Shows_over:
b6 = 0 'reset sleep timer
for b5 = 7 to 0 step -1 'end of playback animation
high b5
pause 100
next b5
pause 250
goto pulse 'goto sleep mode
pulse:
for b0 = 0 to 100 'this program pulses both pwm out puts
pwmout 1,24,b0 'one is on the 0v side of the vu meter
pwmout 2,24,b0 'the other is on the +v side of the ambient lighting
readadc 1,b7 'checki8ng for sound
if pin6 = 0 then goto mode_check 'checking for mode input
if b7 > 20 then goto pwmoff 'if there is sound then exet the loop
pause 10
next b0
for b0 = 100 to 5 step -1
pwmout 1,24,b0
pwmout 2,24,b0
readadc 1,b7
if pin6 = 0 then goto mode_check
if b7 > 20 then goto pwmoff
pause 10
next b0
goto pulse
pwmoff:
pwmout 1,off 'this program resets the pwm output
pwmout 2,off
goto VU
Top_LevelVU:
readadc 1,b0 'this program is the same as abouve but with a top level indication
b2 = 7
for b1 = 0 to 105 step 15
if b0=0 then inc b6
end if
if b6 = 50 then goto shows_overTL
if pin6 = 0 then goto mode_check
if b0 > b1 then high b2 else goto readagainTL
endif
dec b2
b6 = 0
next b1
readagainTL:
readadc 1,b3
if b3 < b0 then goto lights_outTL
if pin6 = 0 then goto mode_check
goto Top_LevelVU
lights_outTL:
b3 = 0
for b1 = 120 to 15 step -15
if b2 > 0 then high b2 'relighting the top level led
end if
if b0 =< b1 then low b3 else goto Top_LevelVU
end if
if pin6 = 0 then goto mode_check
inc b3
low b2
if b2 = 7 then goto Top_LevelVU
next b1
goto Top_LevelVU
Shows_overTL:
b6 = 0
for b5 = 7 to 0 step -1
high b5
pause 100
next b5
pause 250
goto pulseTL
pulseTL:
for b0 = 0 to 100
pwmout 1,24,b0
pwmout 2,24,b0
readadc 1,b7
if pin6 = 0 then goto mode_check
if b7 > 20 then goto pwmoffTL
pause 10
next b0
for b0 = 100 to 5 step -1
pwmout 1,24,b0
pwmout 2,24,b0
readadc 1,b7
if pin6 = 0 then goto mode_check
if b7 > 20 then goto pwmoffTL
pause 10
next b0
goto pulseTL
pwmoffTL:
pwmout 1,off
pwmout 2,off
pause 100
goto Top_LevelVU