Plastic toys are great for hacking, modding and improving using Crickit! This box o' gears is fun for about 10 minutes...but when you add motors, sensors and robotics you can make cool interactive art
This example shows how to use the light sensor on the Circuit Playground Express to trigger a motor to rotate. With some audio effects it becomes a Force trainer, or a moving Theremin





CircuitPython Code For "Force Wave" demo
This project is pretty simple, it looks to see when the light sensor is shaded by your hand and changes the motor from running to off or vice versa.
import time from busio import I2C import analogio from adafruit_seesaw.seesaw import Seesaw from adafruit_seesaw.pwmout import PWMOut from adafruit_motor import motor import board light = analogio.AnalogIn(board.LIGHT) print("Wave on/off to turn") # Create seesaw object i2c = I2C(board.SCL, board.SDA) seesaw = Seesaw(i2c) # Create one motor on seesaw PWM pins 22 & 23 motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23)) motor_a.throttle = 0 # motor is stopped while True: print((light.value,)) # light value drops when a hand passes over if light.value < 4000: if motor_a.throttle: motor_a.throttle = 0 else: motor_a.throttle = 1 # full speed forward while light.value < 5000: # wait till hand passes over completely pass time.sleep(0.1)
CircuitPython Code For "Theremin" demo
We can adapt the code above to speed up or slow down the motor based on how far our hand is. The darker the sensor, the faster the motor spins!
import time from busio import I2C import analogio from adafruit_seesaw.seesaw import Seesaw from adafruit_seesaw.pwmout import PWMOut from adafruit_motor import motor import board light = analogio.AnalogIn(board.LIGHT) print("Theramin-like turning") # Create seesaw object i2c = I2C(board.SCL, board.SDA) seesaw = Seesaw(i2c) # Create one motor on seesaw PWM pins 22 & 23 motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23)) motor_a.throttle = 0 # motor is stopped def map_range(x, in_min, in_max, out_min, out_max): # 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) while True: print((light.value,)) motor_a.throttle = map_range(light.value, 500, 8000, 1.0, 0) time.sleep(0.1)