DEVICE_ADDRESS = 0x39 # device address of APDS9960 board A_DEVICE_REGISTER_1 = 0xA2 # a control register on the APDS9960 board A_DEVICE_REGISTER_2 = 0xA3 # another control register on the APDS9960 board class DeviceControl: #pylint: disable-msg=too-few-public-methods def __init__(self, i2c): self.i2c_device = i2c # self.i2c_device required by RWBit class setting1 = RWBits(2, A_DEVICE_REGISTER_1, 6) # 2 bits: bits 6 & 7 setting2 = RWBits(2, A_DEVICE_REGISTER_2, 5) # 2 bits: bits 5 & 6 # The follow is for I2C communications comm_port = I2C(SCL, SDA) device = I2CDevice(comm_port, DEVICE_ADDRESS) settings = DeviceControl(device) # set the bits in the device settings.setting1 = 0 settings.setting2 = 3 # display the device values for the bits print("setting1: {}; setting2: {}".format(settings.setting1, settings.setting2)) # toggle the bits settings.setting1 = 3 settings.setting2 = 0 # display the device values for the bits print("setting1: {}; setting2: {}".format(settings.setting1,
# Set to your Adafruit IO username. # (go to https://accounts.adafruit.com to find your username) ADAFRUIT_IO_USERNAME = '******' # Create an instance of the REST client. aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY) try: # if we have a 'color' feed color = aio.feeds('color') except RequestError: # create an `color` feed feed = Feed(name='color') color = aio.create_feed(feed) # Create the I2C bus interface. i2c_bus = I2C(SCL, SDA) # Create a simple PCA9685 class instance. pca = PCA9685(i2c_bus) pca.frequency = 60 prev_color = '#000000' def map_range(x, in_min, in_max, out_min, out_max): """re-maps a number from one range to another.""" mapped = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min if out_min <= out_max: return max(min(mapped, out_max), out_min) return min(max(mapped, out_max), out_min)
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense """Simple example of the LTR559 library.""" import time from board import SCL, SDA from busio import I2C from pimoroni_circuitpython_ltr559 import Pimoroni_LTR559 I2C_BUS = I2C(SCL, SDA) LTR559 = Pimoroni_LTR559(I2C_BUS) while True: print(LTR559.lux) # Get Lux value from light sensor print(LTR559.prox) # Get Proximity value from proximity sensor time.sleep(1.0)
# SPDX-FileCopyrightText: 2018 Limor Fried for Adafruit Industries # # SPDX-License-Identifier: MIT # CircuitPython 3.0 CRICKIT demo import time import board from adafruit_motor import servo, motor from adafruit_seesaw.pwmout import PWMOut from adafruit_seesaw.seesaw import Seesaw from busio import I2C i2c = I2C(board.SCL, board.SDA) ss = Seesaw(i2c) print("Bubble machine!") SERVOS = True DCMOTORS = True # Create 4 Servos servos = [] if SERVOS: for ss_pin in (17, 16, 15, 14): pwm = PWMOut(ss, ss_pin) pwm.frequency = 50 _servo = servo.Servo(pwm) _servo.angle = 90 # starting angle, middle servos.append(_servo)
import sys import time import adafruit_bno055 from busio import I2C from board import SDA, SCL i2c = I2C(SCL, SDA) sensor = adafruit_bno055.BNO055(i2c, 0x28) while True: sensor.accelerometer sensor.gyroscope sensor.magnetometer sensor.quaternion sensor.linear_acceleration time.sleep(1)