init:
pwmout 1,255,0 'turn on PWM signal for brakes
pwmout 2,255,0 'tuen on PWM signal for markers
main:
readadc 0,b0 'signal fade in time
readadc 1,b1 'signal fade out time
symbol GOING_UP = b8
symbol GOING_DOWN = b9
symbol direction = b10
symbol counter = b11
symbol COUNT_NEEDED = b12
readadc 2,b2 'PWM duty cycle for marker lights
b4 = 4
w3 = b4 * b2
If direction = GOING_UP Then
If b2 >= b6 Then
b6 = b2
counter = 0
Else
if b2 < b6-1 or counter <= COUNT_NEEDED then
b6 = b2
direction = GOING_DOWN
counter = 0
Else
counter = counter - 1
End If
End If
Else
If b2 <= b6 Then
b6 = b2
counter = 0
Else
If b2 > b6+1 Or counter >= COUNT_NEEDED Then
b6 = b2
direction = GOING_UP
counter = 0
Else
counter = counter + 1
End If
End If
End If
readadc 3,b3 'PWM duty cycle for brake lights
b5 = 4
w4 = b5 * b3
pwmduty 1,w4 'update PWMduty for brakes
if pin1 = 1 then pwmduty 2,w3 'if pin1 goes high turn on marker lights
end if
if pin1 = 0 then pwmduty 2,0 'if pin1 goes low turn off marker lights
end if
if pin3 = 1 and pin2 = 1 then flashhazard
if pin3 = 1 then flashleft
if pin2 = 1 then flashright
if pin3 = 0 and pin2 = 0 then main
goto main
flashleft:
high portc 6 'turn v.regs on for left side
high 0 'first bank of LEDs high
pause b0 'pause for fade in time
high 1
pause b0
high 2
pause b0
high 3
pause b0
high 4
pause b0
high 5
pause b0
high 6
pause b0
high 7
pause b1 'keep last bank high for fade out time
pause b1
low 7 'last bank to turn on now goes off
pause b1 'pause for fade out time
low 6
pause b1
low 5
pause b1
low 4
pause b1
low 3
pause b1
low 2
pause b1
low 1
pause b1
low 0
pause b1
low portc 6 'turn left side regs off
goto main
flashright:
high portc 5 'turn v.regs on for right side
high 0 'first bank of LEDs high
pause b0 'pause for fade in time
high 1
pause b0
high 2
pause b0
high 3
pause b0
high 4
pause b0
high 5
pause b0
high 6
pause b0
high 7
pause b1 'keep last bank high for fade out time
pause b1
low 7 'last bank to turn on now goes off
pause b1 'pause for fade out time
low 6
pause b1
low 5
pause b1
low 4
pause b1
low 3
pause b1
low 2
pause b1
low 1
pause b1
low 0
pause b1
low portc 5 'turn right side regs off
goto main
flashhazard:
high portc 6 'turn v.regs on for left side
high portc 5 'turn v.regs on for right side
high 0 'first bank of LEDs high
pause b0 'pause for fade in time
high 1
pause b0
high 2
pause b0
high 3
pause b0
high 4
pause b0
high 5
pause b0
high 6
pause b0
high 7
pause b1 'keep last bank high for fade out time
pause b1
low 7 'last bank to turn on now goes off
pause b1 'pause for fade out time
low 6
pause b1
low 5
pause b1
low 4
pause b1
low 3
pause b1
low 2
pause b1
low 1
pause b1
low 0
pause b1
low portc 6 'turn left side regs off
low portc 5 'tuen right side regs off
goto main