| Posted: 12:26pm 12 May 2025 |
|
|
|
Good afternoon from a wet Wales.
Let's say I have 6 LEDs on on GP2 - GP7.
I can set them for outout with SETPIN GP2, DOUT etc and control them with PIN(GP2) = 1 etc.
I am randomly lighting one of the 6 (other five off). Currently doing this with a clunky Select Case:
pseudoish code:
Select Case LEDon CASE 1 PIN(GP2) = 1 PIN(GP3) = 0 PIN(GP4) = 0 PIN(GP5) = 0 PIN(GP6) = 0 PIN(GP7) = 0 CASE 2 - 'etc etc
Questions:
(1) Is there a way to set all pins low in one simple command? ie PIN(ALL) = 0 (I could abstract this to a SUB, setting each pin individually, so asking in case I've missed something) -- that way I only need to set the pin that is on.
(2) Ideally what I want to do is:
PIN (INT(RND * (m - n + 1)) + n) = 1 where n=2, m=6 so that it picks a random pin from 2 to 6. Is there an easy way to achieve this? I could construct the "GP2" part as a string and use "EVAL" - but that feels clunky. Again, asking in case I've missed the obvious.
Cheers all. |