This demo is how to control a light sensitive CRICKIT with NeoPixel “theremin” and sound. Video & Code.
“There is no sanctuary” – Logan’s Run.
Crickit – A Creative Robotics & Interactive Construction Kit. It’s an add-on to our popular Circuit Playground Express that lets you #MakeRobotFriend using CircuitPython, MakeCode, Arduino, etc.. robotics, arts, crafts, audio animatronics, sensors, agriculture/robot farming, physical computing, kinetic sculptures, science experiments, telescope control…
The Crickit is powered by seesaw, an I2C-to-whatever bridge firmware. So you only need to use two data pins to control the huge number of inputs and outputs on the Crickit. All those timers, PWMs, sensors are offloaded to the co-processor.
https://www.adafruit.com/crickit & more videos.
import time
#import math
import array
from digitalio import DigitalInOut, Direction, Pull
import analogio
import supervisor
import audioio
import board
import neopixel
# NeoPixels
pixel_pin = board.A1
num_pixels = 30
pixels = neopixel.NeoPixel(pixel_pin, num_pixels,
brightness=1, auto_write=False)
pixels.fill((0, 0, 0))
pixels.show()
ring = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=1)
ring.fill((255, 0, 0))
# Light sensor
light = analogio.AnalogIn(board.LIGHT)
BRIGHT = 40000
DARK = 10000
ACTIVITY_THRESHOLD = 20000
# button
button_a = DigitalInOut(board.BUTTON_A)
button_a.direction = Direction.INPUT
button_a.pull = Pull.DOWN
# audio output
cpx_audio = audioio.AudioOut(board.A0)
def play_file(wavfile):
with open(wavfile, "rb") as f:
wav = audioio.WaveFile(f)
cpx_audio.play(wav)
while cpx_audio.playing:
pass
# Generate one period of wave.
length = 8000 // 440
wave_array = array.array("H", [0] * length)
for i in range(length):
# Sine wave
# wave_array[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
# Triangle wave
# wave_array[i] = int( i/length * (2 ** 16))
# Saw wave
if i ACTIVITY_THRESHOLD:
timeout = time.monotonic() # reset our timeout
# 4 seconds no activity
if time.monotonic() - timeout > 4:
break
pixels.fill((255, 0, 0))
pixels.show()
play_file("03_no_sanctuary.wav")
time.sleep(1)
# restart
supervisor.reload()
from Adafruit Industries – Makers, hackers, artists, designers and engineers! https://ift.tt/2sor8gu
via IFTTT
Комментариев нет:
Отправить комментарий