Beispiel #1
0
# measured on the Expander Pi Vref pin.
adc.set_adc_refvoltage(4.096)

while True:
    # clear the console
    os.system('clear')

    # read the date from the RTC in ISO 8601 format and print it to the screen
    print 'Date: ' + rtc.read_date()
    print ''
    print 'ADC: '
    print 'Channel 1: ' + str(adc.read_adc_voltage(1, 0))
    print 'Channel 2: ' + str(adc.read_adc_voltage(2, 0))
    print 'Channel 3: ' + str(adc.read_adc_voltage(3, 0))
    print 'Channel 4: ' + str(adc.read_adc_voltage(4, 0))
    print 'Channel 5: ' + str(adc.read_adc_voltage(5, 0))
    print 'Channel 6: ' + str(adc.read_adc_voltage(6, 0))
    print 'Channel 7: ' + str(adc.read_adc_voltage(7, 0))
    print 'Channel 8: ' + str(adc.read_adc_voltage(8, 0))
    print ''
    print 'IO: '
    print 'Pin 1: ' + str(io.read_pin(1))
    print 'Pin 2: ' + str(io.read_pin(2))
    print 'Pin 3: ' + str(io.read_pin(3))
    print 'Pin 4: ' + str(io.read_pin(4))
    print 'Pin 5: ' + str(io.read_pin(5))
    print 'Pin 6: ' + str(io.read_pin(6))
    print 'Pin 7: ' + str(io.read_pin(7))
    print 'Pin 8: ' + str(io.read_pin(8))
    time.sleep(0.2)
as 1 unless the pin is connected to ground.

Initialise the IO class and create an instance called io.
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
io = IO(bus)

# We will read the inputs 1 to 8 from the I/O bus so set port 0 to be
# inputs and enable the internal pull-up resistors
io.set_port_direction(0, 0xFF)
io.set_port_pullups(0, 0xFF)

while True:
    # clear the console
    os.system('clear')

    # read the pins 1 to 8 and print the results
    print ('Pin 1: ' + str(io.read_pin(1)))
    print ('Pin 2: ' + str(io.read_pin(2)))
    print ('Pin 3: ' + str(io.read_pin(3)))
    print ('Pin 4: ' + str(io.read_pin(4)))
    print ('Pin 5: ' + str(io.read_pin(5)))
    print ('Pin 6: ' + str(io.read_pin(6)))
    print ('Pin 7: ' + str(io.read_pin(7)))
    print ('Pin 8: ' + str(io.read_pin(8)))

    # wait 0.5 seconds before reading the pins again
    time.sleep(0.1)
io = IO()

# We will read the inputs 1 to 16 from the I/O bus so set port 0 and port 1 to be
# inputs and enable the internal pull-up resistors
io.set_port_direction(0, 0xFF)
io.set_port_pullups(0, 0xFF)

io.set_port_direction(1, 0xFF)
io.set_port_pullups(1, 0xFF)

while True:
    # clear the console
    os.system('clear')

    # read the pins 1 to 16 and print the results
    print ('Pin 1:  ' + str(io.read_pin(1)))
    print ('Pin 2:  ' + str(io.read_pin(2)))
    print ('Pin 3:  ' + str(io.read_pin(3)))
    print ('Pin 4:  ' + str(io.read_pin(4)))
    print ('Pin 5:  ' + str(io.read_pin(5)))
    print ('Pin 6:  ' + str(io.read_pin(6)))
    print ('Pin 7:  ' + str(io.read_pin(7)))
    print ('Pin 8:  ' + str(io.read_pin(8)))
    print ('Pin 9:  ' + str(io.read_pin(9)))
    print ('Pin 10: ' + str(io.read_pin(10)))
    print ('Pin 11: ' + str(io.read_pin(11)))
    print ('Pin 12: ' + str(io.read_pin(12)))
    print ('Pin 13: ' + str(io.read_pin(13)))
    print ('Pin 14: ' + str(io.read_pin(14)))
    print ('Pin 15: ' + str(io.read_pin(15)))
    print ('Pin 16: ' + str(io.read_pin(16)))
Beispiel #4
0
io = IO()

# We will read the inputs 1 to 16 from the I/O bus so set port 0 and port 1 to be
# inputs and enable the internal pull-up resistors
io.set_port_direction(0, 0xFF)
io.set_port_pullups(0, 0xFF)

io.set_port_direction(1, 0xFF)
io.set_port_pullups(1, 0xFF)

while True:
    # clear the console
    os.system('clear')

    # read the pins 1 to 16 and print the results
    print('Pin 1:  ' + str(io.read_pin(1)))
    print('Pin 2:  ' + str(io.read_pin(2)))
    print('Pin 3:  ' + str(io.read_pin(3)))
    print('Pin 4:  ' + str(io.read_pin(4)))
    print('Pin 5:  ' + str(io.read_pin(5)))
    print('Pin 6:  ' + str(io.read_pin(6)))
    print('Pin 7:  ' + str(io.read_pin(7)))
    print('Pin 8:  ' + str(io.read_pin(8)))
    print('Pin 9:  ' + str(io.read_pin(9)))
    print('Pin 10: ' + str(io.read_pin(10)))
    print('Pin 11: ' + str(io.read_pin(11)))
    print('Pin 12: ' + str(io.read_pin(12)))
    print('Pin 13: ' + str(io.read_pin(13)))
    print('Pin 14: ' + str(io.read_pin(14)))
    print('Pin 15: ' + str(io.read_pin(15)))
    print('Pin 16: ' + str(io.read_pin(16)))