ich baue an einer Raffstore Steuerung und habe dazu folgendes Testskript geschrieben.
Code: Alles auswählen
#!/usr/bin/python
import sys
import smbus
bus = smbus.SMBus(1)
# chip adressen
chip_rauf = (0x20)
chip_runter = (0x00)
kueche = [18,1] # GPA0
esszimmer1 = [18,2] # GPA1
bus.write_byte_data(0x20,0x00,0x00) # Set all of bank A to outputs
bus.write_byte_data(0x20,0x01,0x00) # Set all of bank B to outputs
list = []
def main():
global list
list = kueche
runlist(chip_rauf)
sys.exit()
def runlist(chip):
for i in list:
bus.write_byte_data(chip, i[0], i[1])
if __name__ == '__main__':
main()
Beim Aufruf bekomme ich den Fehler:
pi@raspberrypi ~/work/python $ ./test.py
Traceback (most recent call last):
File "./test.py", line 32, in <module>
main()
File "./test.py", line 24, in main
runlist(chip_rauf)
File "./test.py", line 29, in runlist
bus.write_byte_data(chip, i[0], i[1])
TypeError: 'int' object has no attribute '__getitem__'
Wenn ich
>>> bus.write_byte_data(0x20, list[0], list[1])
ohne der for Schleife aufrufe funktioniert alles...
woran liegt das
Danke im Voraus