import time

    from IOPi import IOPi
except ImportError:
    print("Failed to import IOPi from python system path")
    print("Importing from parent folder instead")
        import sys
        from IOPi import IOPi
    except ImportError:
        raise ImportError(
            "Failed to import library from parent folder")

def main():
    Main program function

    # create two instances of the IoPi class called iobus1 and iobus2 and set
    # the default i2c addresses
#     iobus1 = IOPi(0x20)  # bus 1 will be inputs
    iobus2 = IOPi(0x21)  # bus 2 will be outputs

    # Each bus is divided up two 8 bit ports.  Port 0 controls pins 1 to 8,
    # Port 1 controls pins 9 to 16.
    # We will read the inputs on pin 1 of bus 1 so set port 0 to be inputs and
    # enable the internal pull-up resistors
#     iobus1.set_port_direction(0, 0xFF)
#     iobus1.set_port_pullups(0, 0xFF)

    # We will write to the output pin 1 on bus 2 so set port 0 to be outputs
    # and turn off the pins on port 0
    iobus2.set_port_direction(0, 0x00)
    iobus2.write_port(0, 0x00)

    while True:

        # read pin 1 on bus 1.  If pin 1 is high set the output on
        # bus 2 pin 1 to high, otherwise set it to low.
        # connect pin 1 on bus 1 to ground to see the output on
        # bus 2 pin 1 change state.

            iobus2.write_pin(1, 1)
            iobus2.write_pin(1, 0)

        # wait 0.1 seconds before reading the pins again

if __name__ == "__main__":
  • What is your question? – joan Nov 16 '19 at 13:19
  • Just posting a code snippet will not help much to understand your problem. Can you please elaborate your question? Please take the short Tour and visit the Help Center to get an idea how things work here. – Ingo Nov 17 '19 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.