Last active
June 6, 2025 03:26
-
-
Save stonehippo/0ec906d0c09d1c80a0dce35c153ae5fc to your computer and use it in GitHub Desktop.
A little robotic surprise for the quarterly, written in CircuitPython
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CIRCUITPY_BLE_NAME="WhatsInTheBox?" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import board | |
import adafruit_ticks | |
from adafruit_motorkit import MotorKit | |
from neopixel import NeoPixel | |
from rainbowio import colorwheel | |
from adafruit_ble import BLERadio | |
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement | |
from adafruit_ble.services.nordic import UARTService | |
pixels = NeoPixel(board.NEOPIXEL, 1, brightness=0.1) | |
pixels.fill(colorwheel(24)) | |
kit = MotorKit() | |
ble = BLERadio() | |
# ble.name = "WhatsInTheBox" # Config'ed in settings.toml | |
uart = UARTService() | |
advertisement = ProvideServicesAdvertisement(uart) | |
def pulse(motor, throttle = 1.0, interval = 0.25, pause=None, count = 5): | |
for _ in range(count): | |
motor.throttle = throttle | |
time.sleep(interval) | |
if pause: | |
motor.throttle=None | |
time.sleep(pause) | |
motor.throttle = -(throttle) | |
time.sleep(interval) | |
if pause: | |
motor.throttle=None | |
time.sleep(pause) | |
motor.throttle = None | |
def send_message(msg): | |
uart.write(msg.encode("utf-8")) | |
while True: | |
print("Advertising BLE services") | |
ble.start_advertising(advertisement) | |
while not ble.connected: | |
pass | |
ble.stop_advertising() | |
print("BLE connected") | |
while ble.connected: | |
send_message("pulsing m1") | |
pulse(kit.motor1) | |
send_message("pulsing_m2") | |
pulse(kit.motor2, interval=1.5, pause=0.5) | |
kit.motor1.throttle = None | |
kit.motor1.throttle = None | |
print("BLE disconnected") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment