From cbc21e52be07b6a4b81996243683ae644820a2cc Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Tue, 28 Feb 2023 08:48:15 +0000 Subject: [PATCH] Galactic/Cosmic Unicorn: Add sound to 80s computer. --- .../numpy/eighties_super_computer.py | 35 ++++++++++++++++--- .../numpy/eighties_super_computer.py | 35 ++++++++++++++++--- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/micropython/examples/cosmic_unicorn/numpy/eighties_super_computer.py b/micropython/examples/cosmic_unicorn/numpy/eighties_super_computer.py index 5a1573d0..7b0b4a2d 100644 --- a/micropython/examples/cosmic_unicorn/numpy/eighties_super_computer.py +++ b/micropython/examples/cosmic_unicorn/numpy/eighties_super_computer.py @@ -1,7 +1,7 @@ import gc import time import random -from cosmic import CosmicUnicorn +from cosmic import CosmicUnicorn, Channel from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN, PEN_P8 from ulab import numpy @@ -13,14 +13,27 @@ Experiment with the damping, number of spawns and intensity to change the effect # MAXIMUM OVERKILL # machine.freq(250_000_000) +DAMPING_FACTOR = 0.95 +NUMBER_OF_LIGHTS = 10 +INTENSITY = 20 + +volume = 0.5 + cu = CosmicUnicorn() cu.set_brightness(0.5) graphics = PicoGraphics(DISPLAY_COSMIC_UNICORN, pen_type=PEN_P8) +boopety_beepety = cu.synth_channel(0) +boopety_beepety.configure( + waveforms=Channel.SQUARE | Channel.SINE, + attack=0.1, + decay=0.1, + sustain=0.0, + release=0.5, + volume=volume +) -DAMPING_FACTOR = 0.95 -NUMBER_OF_LIGHTS = 10 -INTENSITY = 20 +cu.play_synth() # Fill palette with a yellow r, g, b = (230, 150, 0) @@ -60,12 +73,26 @@ while True: if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): cu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN): + volume -= 0.1 + volume = max(0.0, volume) + boopety_beepety.volume(volume) + + if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP): + volume += 0.1 + volume = min(1.0, volume) + boopety_beepety.volume(volume) + tstart = time.ticks_ms() gc.collect() update() draw() tfinish = time.ticks_ms() + # Play random notes between 100 and 880Hz for a computery effect + boopety_beepety.frequency(random.randint(100, 880)) + boopety_beepety.trigger_attack() + total = tfinish - tstart t_total += total t_count += 1 diff --git a/micropython/examples/galactic_unicorn/numpy/eighties_super_computer.py b/micropython/examples/galactic_unicorn/numpy/eighties_super_computer.py index 65c06433..0f6787ef 100644 --- a/micropython/examples/galactic_unicorn/numpy/eighties_super_computer.py +++ b/micropython/examples/galactic_unicorn/numpy/eighties_super_computer.py @@ -1,7 +1,7 @@ import gc import time import random -from galactic import GalacticUnicorn +from galactic import GalacticUnicorn, Channel from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN, PEN_P8 from ulab import numpy @@ -13,14 +13,27 @@ Experiment with the damping, number of spawns and intensity to change the effect # MAXIMUM OVERKILL # machine.freq(250_000_000) +DAMPING_FACTOR = 0.95 +NUMBER_OF_LIGHTS = 10 +INTENSITY = 20 + gu = GalacticUnicorn() gu.set_brightness(0.5) graphics = PicoGraphics(DISPLAY_GALACTIC_UNICORN, pen_type=PEN_P8) +volume = 0.5 -DAMPING_FACTOR = 0.95 -NUMBER_OF_LIGHTS = 10 -INTENSITY = 20 +boopety_beepety = gu.synth_channel(0) +boopety_beepety.configure( + waveforms=Channel.SQUARE | Channel.SINE, + attack=0.1, + decay=0.1, + sustain=0.0, + release=0.5, + volume=volume +) + +gu.play_synth() # Fill palette with a yellow r, g, b = (230, 150, 0) @@ -60,12 +73,26 @@ while True: if gu.is_pressed(GalacticUnicorn.SWITCH_BRIGHTNESS_DOWN): gu.adjust_brightness(-0.01) + if gu.is_pressed(GalacticUnicorn.SWITCH_VOLUME_DOWN): + volume -= 0.1 + volume = max(0.0, volume) + boopety_beepety.volume(volume) + + if gu.is_pressed(GalacticUnicorn.SWITCH_VOLUME_UP): + volume += 0.1 + volume = min(1.0, volume) + boopety_beepety.volume(volume) + tstart = time.ticks_ms() gc.collect() update() draw() tfinish = time.ticks_ms() + # Play random notes between 100 and 880Hz for a computery effect + boopety_beepety.frequency(random.randint(100, 880)) + boopety_beepety.trigger_attack() + total = tfinish - tstart t_total += total t_count += 1