Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8609

MicroPython • Re: gotta be a better way

$
0
0
You can create a list of outputs ...

Code:

output = [    machine.Pin(15, machine.Pin.OUT),    machine.Pin(14, machine.Pin.OUT),    machine.Pin(13, machine.Pin.OUT),    machine.Pin(9, machine.Pin.OUT),    machine.Pin(8, machine.Pin.OUT),    machine.Pin(7, machine.Pin.OUT),    machine.Pin(6, machine.Pin.OUT),    machine.Pin(5, machine.Pin.OUT),    machine.Pin(4, machine.Pin.OUT),]
And then do this, untested ...

Code:

import randomwhile True:    if snsr_pir.value() == 0:        n = random.randrange(len(output))        output[n].value(1)        time.sleep(0.8)        output[n].value(0)        time.sleep(60)
If you put your code between [code] ... [/code] tags when posting it will preserve the indentation of your code as above.

Statistics: Posted by hippy — Tue Aug 05, 2025 7:24 pm



Viewing all articles
Browse latest Browse all 8609

Trending Articles