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()


Adafruit publishes a wide range of writing and video content, including interviews and reporting on the maker market and the wider technology world. Our standards page is intended as a guide to best practices that Adafruit uses, as well as an outline of the ethical standards Adafruit aspires to. While Adafruit is not an independent journalistic institution, Adafruit strives to be a fair, informative, and positive voice within the community – check it out here: adafruit.com/editorialstandards

Join Adafruit on Mastodon

Adafruit is on Mastodon, join in! adafruit.com/mastodon

Stop breadboarding and soldering – start making immediately! Adafruit’s Circuit Playground is jam-packed with LEDs, sensors, buttons, alligator clip pads and more. Build projects with Circuit Playground in a few minutes with the drag-and-drop MakeCode programming site, learn computer science using the CS Discoveries class on code.org, jump into CircuitPython to learn Python and hardware together, TinyGO, or even use the Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for CircuitPython, MakeCode, and Arduino. It has a powerful processor, 10 NeoPixels, mini speaker, InfraRed receive and transmit, two buttons, a switch, 14 alligator clip pads, and lots of sensors: capacitive touch, IR proximity, temperature, light, motion and sound. A whole wide world of electronics and coding is waiting for you, and it fits in the palm of your hand.

Have an amazing project to share? The Electronics Show and Tell is every Wednesday at 7pm ET! To join, head over to YouTube and check out the show’s live chat – we’ll post the link there.

Join us every Wednesday night at 8pm ET for Ask an Engineer!

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

CircuitPython – The easiest way to program microcontrollers – CircuitPython.org


Maker Business — “Packaging” chips in the US

Wearables — Enclosures help fight body humidity in costumes

Electronics — Transformers: More than meets the eye!

Python for Microcontrollers — Python on Microcontrollers Newsletter: Silicon Labs introduces CircuitPython support, and more! #CircuitPython #Python #micropython @ThePSF @Raspberry_Pi

Adafruit IoT Monthly — Guardian Robot, Weather-wise Umbrella Stand, and more!

Microsoft MakeCode — MakeCode Thank You!

EYE on NPI — Maxim’s Himalaya uSLIC Step-Down Power Module #EyeOnNPI @maximintegrated @digikey

New Products – Adafruit Industries – Makers, hackers, artists, designers and engineers! — #NewProds 7/19/23 Feat. Adafruit Matrix Portal S3 CircuitPython Powered Internet Display!

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.