MrDEB
Well-Known Member
Am attempting to put all my leds in a matrix thus freeing up some pin.
In order to allow an led to stay ON or OFF I am using TOGGLE. This code works pretty good. I attempted to use boolean but don't really need it?
The led stays on until the button is pressed a second time.
I inserted the delayms to aid in a debounce. it works better than without.
any suggestions on improvements?
while true
if sw0 = 0 //pushbutton 0
then
delayms(50)
'player1 = true
toggle (led0) //led0
else sw0 = 1
end if
if sw1 = 0
then
delayms(50)
'player2 = true
toggle (led1)
else sw1 = 1
end if
if sw2 = 0
then
delayms(50)
' player3 = true
toggle (led2)
else sw2 = 1
end if
if sw3 = 0
then
delayms(50)
' player4 = true
toggle (led3)
else sw3 = 1
end if
if sw4 = 0
then
delayms(50)
' player5 = true
toggle (led4)
else sw4 = 1
end if
if sw5=0
then
delayms(50)
' player5 = true
toggle (led5)
else sw5 = 1
end if
if sw6 = 0
then
delayms(50)
' player5 = true
toggle (led6)
else sw6 = 1
end if
if sw7=0
then
delayms(50)
toggle(led7)
endif
wend
In order to allow an led to stay ON or OFF I am using TOGGLE. This code works pretty good. I attempted to use boolean but don't really need it?
The led stays on until the button is pressed a second time.
I inserted the delayms to aid in a debounce. it works better than without.
any suggestions on improvements?
while true
if sw0 = 0 //pushbutton 0
then
delayms(50)
'player1 = true
toggle (led0) //led0
else sw0 = 1
end if
if sw1 = 0
then
delayms(50)
'player2 = true
toggle (led1)
else sw1 = 1
end if
if sw2 = 0
then
delayms(50)
' player3 = true
toggle (led2)
else sw2 = 1
end if
if sw3 = 0
then
delayms(50)
' player4 = true
toggle (led3)
else sw3 = 1
end if
if sw4 = 0
then
delayms(50)
' player5 = true
toggle (led4)
else sw4 = 1
end if
if sw5=0
then
delayms(50)
' player5 = true
toggle (led5)
else sw5 = 1
end if
if sw6 = 0
then
delayms(50)
' player5 = true
toggle (led6)
else sw6 = 1
end if
if sw7=0
then
delayms(50)
toggle(led7)
endif
wend
Last edited by a moderator: