I have to write a program which selects a random led and lights it up ,however I am having trouble getting the RANDOM
function work. I have included the code i have below.
main:
RANDOM w0
w1 = w0// 10+ 1
SELECTCASE w1
Case1:
high b.1
pause 1000
low b.1
Case2:
high b.2
pause 1000
low b.2
ENDSELECT
goto main
Two observations:
1) The code w1 = w0// 10+ 1
sets w1
to a value between 1 and 10, but your select case
structure only handles cases 1 and 2. That shouldn't actually be a problem though, as the unhandled values will do nothing - but your code may loop several times before the random sequence produces a 1 or 2. If you want a value between 1 and 2, use w1 = w0 // 2 + 1
.
2) As posted your code has some unnecessary colons and lacks some spaces where they should be, at least according to the manual entry for select case
. I would try correcting these just in case that's the problem.
Aside from that, can you give more detail on what isn't working? Are you sure that your wiring is correct and a high
on those two pins does in fact light the two LEDs? You could try adding sertxd
commands within your case structure to confirm whether the code actually reaches each case.