Skip to content

Instantly share code, notes, and snippets.

@seantibor
Last active May 22, 2019 14:58
Show Gist options
  • Save seantibor/587f3b9e92316910d4c878eeb66f32a5 to your computer and use it in GitHub Desktop.
Save seantibor/587f3b9e92316910d4c878eeb66f32a5 to your computer and use it in GitHub Desktop.
InfinityPlayground Example
from adafruit_circuitplayground.express import cpx
import analogio, time, board, audiobusio, array
infinity_stones = {'Soul': (38, 110, 246),
'Time': (228, 41, 242),
'Mind': (248, 187, 0),
'Reality': (255, 1, 48),
'Power': (255, 211, 0),
'Space': (18, 231, 114)
}
cpx.pixels.brightness = 0.1
NUM_SAMPLES = 100
def snap():
for i in range(2,8):
cpx.pixels[i] = (255, 255, 255)
for i in range(int(cpx.pixels.brightness * 10), 10):
cpx.pixels.brightness = i / 10
time.sleep(0.01)
time.sleep(0.1)
cpx.pixels.brightness = 0.1
mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,
sample_rate=16000, bit_depth=16)
while True:
for i, color in enumerate(infinity_stones.values()):
cpx.pixels[i+2] = color
samples = array.array('H', [0] * NUM_SAMPLES)
mic.record(samples, len(samples))
print(sum(samples) / len(samples))
if sum(samples) / len(samples) > 33000:
snap()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment