Skip to content

Instantly share code, notes, and snippets.

@windoze
Created September 14, 2020 12:19
Show Gist options
  • Save windoze/2ed4aee5400f547b13503f822fba0010 to your computer and use it in GitHub Desktop.
Save windoze/2ed4aee5400f547b13503f822fba0010 to your computer and use it in GitHub Desktop.
# Support lib for RobotBit from [KittenBot](https://www.kittenbot.cn/), works on Micro:bit and Adafruit CLUE
import busio
import neopixel
import pulseio
from adafruit_motor import servo, motor, stepper
from adafruit_pca9685 import PCA9685
from board import SCL, SDA, P0, P16
class RobotBit:
def __init__(self):
self._pca = PCA9685(busio.I2C(SCL, SDA))
self._pca.frequency = 50
# 8 servos
self.s1 = servo.Servo(pca.channels[8])
self.s2 = servo.Servo(pca.channels[9])
self.s3 = servo.Servo(pca.channels[10])
self.s4 = servo.Servo(pca.channels[11])
self.s5 = servo.Servo(pca.channels[12])
self.s6 = servo.Servo(pca.channels[13])
self.s7 = servo.Servo(pca.channels[14])
self.s8 = servo.Servo(pca.channels[15])
self.servos = [
self.s1,
self.s2,
self.s3,
self.s4,
self.s5,
self.s6,
self.s7,
self.s8,
]
# 4 Motors
self.motor1a = motor.DCMotor(pca.channels[0], pca.channels[1])
self.motor1b = motor.DCMotor(pca.channels[2], pca.channels[3])
self.motor2a = motor.DCMotor(pca.channels[4], pca.channels[5])
self.motor2b = motor.DCMotor(pca.channels[6], pca.channels[7])
self.motors = [
self.motor1a,
self.motor1b,
self.motor2a,
self.motor2b,
]
# 2 Steppers
self.stepper1 = stepper.Stepper(pca.channels[0], pca.channels[1], pca.channels[2], pca.channels[3])
self.stepper2 = stepper.Stepper(pca.channels[4], pca.channels[5], pca.channels[6], pca.channels[7])
self.steppers = [
self.stepper1,
self.stepper2,
]
# 4 NeoPixels on P16
self.neopixels = neopixel.NeoPixel(P16, 4, brightness=0, auto_write=False)
# Buzzer
self.buzzer = pulseio.PWMOut(P0, variable_frequency=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment