code.py
1 # SPDX-FileCopyrightText: 2018 Limor Fried for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import time 6 from busio import I2C 7 from adafruit_seesaw.seesaw import Seesaw 8 from adafruit_seesaw.pwmout import PWMOut 9 from adafruit_motor import motor 10 import neopixel 11 import audioio 12 import audiocore 13 import board 14 15 print("The voyages of the CPX-1701!") 16 17 # Create seesaw object 18 i2c = I2C(board.SCL, board.SDA) 19 seesaw = Seesaw(i2c) 20 21 # Create one motor on seesaw PWM pins 22 & 23 22 motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23)) 23 24 # audio output 25 cpx_audio = audioio.AudioOut(board.A0) 26 27 # neopixels! 28 pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=1) 29 pixels.fill((0, 0, 0)) 30 31 # give me a second before starting 32 time.sleep(1) 33 34 motor_a.throttle = 0 # warp drive off 35 36 f = open("01space.wav", "rb") 37 wav = audiocore.WaveFile(f) 38 cpx_audio.play(wav) 39 40 t = time.monotonic() # take a timestamp 41 42 # slowly power up the dilithium crystals 43 for i in range(50): 44 pixels.fill((0, 0, i)) 45 time.sleep(0.05) 46 47 # 6 seconds after audio started... 48 while time.monotonic() - t < 6: 49 pass 50 51 motor_a.throttle = 1 # full warp drive on! 52 53 # wait for music to end 54 while cpx_audio.playing: 55 pass 56 f.close() 57 58 # play the warp drive and theme music! 59 f = open("02warp.wav", "rb") 60 wav = audiocore.WaveFile(f) 61 cpx_audio.play(wav) 62 63 time.sleep(1) 64 65 # blast off! 66 pixels.fill((255, 0, 0)) 67 68 # pulse the warp core 69 while True: 70 for i in range(255, 0, -5): 71 pixels.fill((i, 0, 0)) 72 for i in range(0, 255, 5): 73 pixels.fill((i, 0, 0)) 74 75 # wait for music to end 76 while cpx_audio.playing: 77 pass 78 f.close()