Beispiel #1
0
    try:
        # check to see if hex or decimal arguement
        if '0x' in sys.argv[1]:
            i2c_address = int(sys.argv[1], 16)
        else:
            i2c_address = int(sys.argv[1])
    except ValueError:
        print('Ignoring invalid arguement: ' + str(sys.argv[1]))

# Show the initial address
print('Current i2c address = ' + str(i2c_address) + ' [' + hex(i2c_address) +
      ']')

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
twist = sparkfun_qwiictwist.Sparkfun_QwiicTwist(i2c, i2c_address)

if twist.connected:
    print('Qwiic Twist Example.')
else:
    # if we can't connecct, something is wrong so just quit
    print('Twist does not appear to be connected. Please check wiring.')
    exit()

print('Address: ' + str(i2c_address) + ' [' + hex(i2c_address) + ']' +
      ' Version: ' + twist.version)

text = input(
    'Enter a new I2C address (as a decimal from 8 to 119 or hex 0x08 to 0x77):'
)
Beispiel #2
0
 This program uses the Qwiic Twist CircuitPython Library to
 control the Qwiic Twist RGB Rotrary Encoder over I2C to set
 the knob color to an endless number of random colors.
"""
import sys
from time import sleep
import random

import board
import sparkfun_qwiictwist

# Create bus object using our board's I2C port
i2c = board.I2C()

# Create twist object
twist = sparkfun_qwiictwist.Sparkfun_QwiicTwist(i2c)

print("Qwicc Twist Example 3 Crazy Color")

# Check if connected
if twist.connected:
    print("Twist connected.")
else:
    print("Twist does not appear to be connected. Please check wiring.")
    sys.exit()

print("Type Ctrl-C to exit program.")

# Turn off any color connections
twist.connect_color(0, 0, 0)