import gc import pulseio gc.collect() import adafruit_irremote gc.collect() from adafruit_motor import motor gc.collect() from adafruit_seesaw.seesaw import Seesaw gc.collect() from adafruit_seesaw.pwmout import PWMOut gc.collect() import neopixel gc.collect() import audioio gc.collect() from busio import I2C import board import time print("Blimp!") # Create Infrared reader pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=100, idle_state=True) decoder = adafruit_irremote.GenericDecode() REMOTE_FORWARD = [255, 2, 175, 80] REMOTE_BACKWARD = [255, 2, 239, 16] REMOTE_PAUSE = [255, 2, 127, 128] # Create seesaw object seesaw = Seesaw(I2C(board.SCL, board.SDA)) # Create one motor on seesaw PWM pins 22 & 23 motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23)) motor_a.throttle = 0 # [email protected] pixels = neopixel.NeoPixel(board.NEOPIXEL, 10) # audio file a = audioio.AudioOut(board.A0) def play_audio(wavfile): f = open(wavfile, "rb") wav = audioio.WaveFile(f) a.play(wav) while a.playing: pass f.close() gc.collect() play_audio("overview.wav") t = time.monotonic() while True: command = None # assume no remote commands came in if len(pulsein) > 25: # check in any IR data came in pulses = decoder.read_pulses(pulsein) try: code = decoder.decode_bits(pulses, debug=False) if code in (REMOTE_FORWARD, REMOTE_BACKWARD, REMOTE_PAUSE): # we only listen to a few different codes command = code else: continue # on any failure, lets just restart except: continue if command: if code == REMOTE_FORWARD: play_audio("fan_forward.wav") motor_a.throttle = 1 # full speed forward pixels.fill((255,0,0)) elif code == REMOTE_BACKWARD: play_audio("fan_backward.wav") motor_a.throttle = -1 # full speed backward pixels.fill((0,0,255)) elif code == REMOTE_PAUSE: motor_a.throttle = 0 # stop motor play_audio("fan_stopped.wav") pixels.fill((0,0,0)) time.sleep(0.5) # play yayayay every 3 seconds if (time.monotonic() - t > 3) and motor_a.throttle != 0: t = time.monotonic() play_audio("yayyayyay.wav")
Make a robot friend with Adafruit’s CRICKIT – A Creative Robotics & Interactive Construction Kit. It’s an add-on to our popular Circuit Playground Express, FEATHER and other platforms to make and program robots with CircuitPython, MakeCode, and Arduino. Start controlling motors, servos, solenoids. You also get signal pins, capacitive touch sensors, a NeoPixel driver and amplified speaker output. It complements & extends your boards so you can still use all the goodies on the microcontroller, now you have a robotics playground as well.
Have an amazing project to share? Join the SHOW-AND-TELL every Wednesday night at 7:30pm ET on Google+ Hangouts.
Join us every Wednesday night at 8pm ET for Ask an Engineer!
Maker Business — Fewer startups, and other collateral damage from the 2018 tariffs
Wearables — Light as a Worbla feather
Electronics — How to make your own magnetic field probe!
Biohacking — The State of DNA Analysis in Three Mindmaps
Python for Microcontrollers — One year of CircuitPython weeklies!
Sorry, the comment form is closed at this time.