コード例 #1
0
from time import sleep
import mcp23008 as mcp

buttonpin=6
ledpin=7

dev=mcp.mcp23008()
dev.set_address(0x20)
dev.set_bus(1)
dev.begin()
dev.set_direction(ledpin,dev.OUTPUT)
dev.set_direction(buttonpin,dev.INPUT)
dev.set_pullup(buttonpin,dev.ENABLE)
sleep(0.5)
while 1:
    but=1-dev.gpio(buttonpin)
    dev.set_gpio(ledpin,but)
    sleep(0.1)
コード例 #2
0
ファイル: main.py プロジェクト: io-Jacob/Misc
    # kwargs = {'address': 0x40}
    # si7020_a20 = SI7020_A20(bus, kwargs)

    kwargs = {'address': 0x40}
    sht25 = SHT25(bus, kwargs)

    ##      AIR COMPRESSOR DEMO END               ##

    ##      WAREHOUSE DEMO START DEF        ##
    time.sleep(.1)
    tca9546.change_channel(1)
    time.sleep(.1)

    gpio_output_map =  {0}
    kwargs = {'address': 0x20, 'gpio_output_map': gpio_output_map}
    mcp23008 = mcp23008(bus, kwargs)

    kwargs = {}

    kwargs = {'address': 0x13}
    vcnl4010 = vcnl4010.VCNL4010(bus, kwargs)

    ##      WAREHOUSE DEMO END DEF      ##
except:
    print('definition fail')

def set_certificates(client):
    from iothub_client_cert import CERTIFICATES
    try:
        client.set_option("TrustedCerts", CERTIFICATES)
        print ( "set_option TrustedCerts successful" )
コード例 #3
0
import smbus

# Get I2C bus, this is bus 1
bus = smbus.SMBus(1)

#define which GPIOs are to be used as outputs. By default all GPIOs are defined as inputs.
#pass the number of the GPIOs in a set to the object. 0 is the first relay 1 is the second relay etc.
#for this example we have no relays and don't need this variable
# gpio_output_map =  {}

#kwargs is a Python set that contains the address of your device and the output map to be passed to the object for initialization.
#since I am using the default address and have no outputs I don't need to pass this variable
# kwargs = {'address': 0x20, 'gpio_output_map': gpio_output_map}
#create the MCP23008 object from the MCP23008 library
#the object requires that you pass it the bus object so that it can communicate and share the bus with other chips if necessary
mcp23008 = mcp23008(smbus)

#by default the inputs are floating. I want to pull up input GPIO 4 so I can hook up a simple switch and read its status.
mcp23008.pull_up_gpio(4)

while True :
    #I want to print out the status of GPIO 4. You can set this up in a conditional logic so it can execute whatever you'd like on change.
    gpio_4_status = mcp23008.get_single_gpio_status(4)
    print gpio_4_status
    #if the status of GPIO 4 is high then I want to print out the status of all GPIOs
    if(gpio_4_status):
        #print out the byte that indicates the status of the GPIOs.
        #255 means all GPIOs are high. 0 means all GPIOs are low.
        #if only GPIO 0 is high then the value will be 1, if only GPIO 3 is high the value will be 8
        #the bits in the byte would look like 00000001 (GPIO 0 is 1 aka high) and 00001000 (GPIO 0 is 1 aka high)
        print mcp23008.get_all_gpio_status()