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

MicroPython • Possible to invert GPIO output using registers?

$
0
0
Hello.
I can invert the PWM signal with my Pico for a project like this:

Code:

def pwm_set_polarity(sliceNo,channel,invert):    Addr = 0x40050000 +0x14*sliceNo    if invert:       machine.mem32[Addr]=machine.mem32[Addr] | 0x1 << (2+channel)
I'm wondering if it can be done with just a simple GPIO output e.g.
pin[0].value(1) would output 0v, pin[0].value(0) 3.3v
The reason is I want to invert the state of a relay without having to use external components.

I am setting the state of 4 relays in a loop thus:

Code:

for r in range(4):    rly[r].value(stat & 1 << r)
It would be handy if I didn't have to code it everywhere but let the Pico hardware deal with it in the way it can deal with it for PWM

Statistics: Posted by jimseng — Fri May 10, 2024 6:24 am



Viewing all articles
Browse latest Browse all 4786

Trending Articles