# -*- coding: iso-8859-1 -*- import smbus import time import random bus = smbus.SMBus(1) # Rev 2 Pi DEVICE = 0x20 # Device Adresse (A0-A2 auf Masse gelegt) IODIRA = 0x00 # Pin Register fuer die Richtung IODIRB = 0x01 # Pin Register fuer die Richtung OLATA = 0x14 # Register fuer Ausgabe (GPA) GPIOB = 0x13 # Register fuer Eingabe (GPB) # Definiere GPB Pin 0 als Input (00000001 = 0x1) # Binaer: 0 = Output, 1 = Input bus.write_byte_data(DEVICE,IODIRB,0x10) # Definiere alle GPA Pins als Output (00000000 = 0x00) bus.write_byte_data(DEVICE,IODIRA,0x00) # Setze alle 8 Output bits auf 0 bus.write_byte_data(DEVICE,OLATA,0) # Mögliche Augenzahl 1,2,3,4,5,6 Auge = [0x08, 0x14, 0x1C, 0x55, 0x5D, 0x77] try: while True: Taster = bus.read_byte_data(DEVICE,GPIOB) if Taster & 0b00000001 == 0b00000001: random.shuffle(Auge) i = random.randint(0, 5) bus.write_byte_data(DEVICE,OLATA,Auge[i]) time.sleep(0.02) except KeyboardInterrupt: bus.write_byte_data(DEVICE,OLATA,0x00)