Can somebody please help with my code?
from pyA20.gpio import gpio
from pyA20.gpio import port
pins = ["PA7",'PA3','PG6']
gpio.init()
for pin in pins:
led = port.PA7
gpio.setcfg(port.pin, gpio.OUTPUT)
gpio.output(port.pin, 1)
I get this error:
AttributeError: 'module' object has no attribute 'pin'
I think it's missing the command for fix attributes.
I am unable to install PYA20 on my machine so i can't test this but, this could work out for you. You cannot append a string to an object. In Python the getattr
method allows you to get an object's attribute using a string. Here's how it looks:
from pyA20.gpio import gpio
from pyA20.gpio import port
pins = ["PA7",'PA3','PG6']
gpio.init()
for pin in pins:
led = port.PA7
current_port = getattr(port, pin)
gpio.setcfg(current_port, gpio.OUTPUT)
gpio.output(current_port, 1)