0

Logan’s Theremin Run with CRICKIT NeoPixels & sound @adafruit #adafruit


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.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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 < length/2:
        wave_array[i] = int(i*2/length * (2 ** 16 - 1))
    else:
        wave_array[i] = int((2**16 - 1) - i*2/length * (2 ** 16))
    print((wave_array[i],))
 
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)
 
def wheel(pos):
    # Input a value 0 to 255 to get a color value.
    # The colours are a transition r - g - b - back to r.
    if pos < 85:
        return (int(pos * 3), int(255 - (pos * 3)), 0)
    elif pos < 170:
        pos -= 85
        return (int(255 - (pos * 3)), 0, int(pos * 3))
    else:
        pos -= 170
        return (0, int(pos * 3), int(255 - pos * 3))
 
time.sleep(2)
 
play_file("01_approach.wav")
 
while not button_a.value:
    pass  # wait for it to be pressed
 
if button_a.value:  # A pressed
    while button_a.value:  # wait for release
        pass
 
time.sleep(1)
 
play_file("02_last_day.wav")
 
time.sleep(1)
 
timeout = time.monotonic()
 
while True:
    print((light.value,))
 
    # determine height of pixels
    pixel_height = map_range(light.value, DARK, BRIGHT, 0, num_pixels)
    pixels.fill((0, 0, 0))
    for p in range(pixel_height):
        pixels[p] = wheel(int(p / num_pixels * 255))
        pixels.show()
 
    # determine squeek
    freq = int(map_range(light.value, DARK, BRIGHT, 440, 8800))
    sine_wave = audioio.RawSample(wave_array, channel_count=1, sample_rate=freq)
    cpx_audio.stop()
    cpx_audio.play(sine_wave, loop=True)
 
    # check no activity
    if light.value > 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()

Join 6,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

CircuitPython in 2018 – Python on Microcontrollers is here!

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!

Follow Adafruit on Instagram for top secret new products, behinds the scenes and more https://www.instagram.com/adafruit/


Maker Business — Aquarium troubles: the cost of iteration and troubleshooting with a manufacturers abroad

Wearables — Plastic gem know-how

Electronics — Counting Pin Numbers

Biohacking — Exploring Our Inner Reality : Entopic Visions

Python for Microcontrollers — CircuitPython 3.0.0 Release Candidate 0 released!

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !



No Comments

No comments yet.

Sorry, the comment form is closed at this time.