kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Cosmic: make examples consistent
rodzic
3459cc5f62
commit
8069ae0e8f
|
@ -77,17 +77,17 @@ def update_leds():
|
|||
graphics.set_pen(current_colour)
|
||||
graphics.pixel(x, y)
|
||||
i = i + 1
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
print("LEDs updated!")
|
||||
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
cu = CosmicUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
|
||||
width = CosmicUnicorn.WIDTH
|
||||
height = CosmicUnicorn.HEIGHT
|
||||
|
||||
gu.set_brightness(0.5)
|
||||
cu.set_brightness(0.5)
|
||||
|
||||
# set up the Pico W's onboard LED
|
||||
pico_led = Pin('LED', Pin.OUT)
|
||||
|
@ -114,15 +114,15 @@ timer.init(period=UPDATE_INTERVAL * 1000, mode=Timer.PERIODIC, callback=lambda t
|
|||
while True:
|
||||
# adjust brightness with LUX + and -
|
||||
# LEDs take a couple of secs to update, so adjust in big (10%) steps
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.1)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.1)
|
||||
update_leds()
|
||||
print(f"Brightness set to {gu.get_brightness()}")
|
||||
print(f"Brightness set to {cu.get_brightness()}")
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.1)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.1)
|
||||
update_leds()
|
||||
print(f"Brightness set to {gu.get_brightness()}")
|
||||
print(f"Brightness set to {cu.get_brightness()}")
|
||||
|
||||
# pause for a moment (important or the USB serial device will fail)
|
||||
time.sleep(0.001)
|
||||
|
|
|
@ -38,7 +38,7 @@ MIDNIGHT_VALUE = 0.3
|
|||
|
||||
|
||||
# create cosmic object and graphics surface for drawing
|
||||
gu = CosmicUnicorn()
|
||||
cu = CosmicUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
|
||||
# create the rtc object
|
||||
|
@ -131,7 +131,7 @@ def sync_time():
|
|||
time.sleep(0.2)
|
||||
|
||||
redraw_display_if_reqd()
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
if max_wait > 0:
|
||||
print("Connected")
|
||||
|
@ -207,23 +207,23 @@ def redraw_display_if_reqd():
|
|||
|
||||
# set the font
|
||||
graphics.set_font("bitmap8")
|
||||
gu.set_brightness(0.5)
|
||||
cu.set_brightness(0.5)
|
||||
|
||||
sync_time()
|
||||
|
||||
while True:
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_A):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_A):
|
||||
sync_time()
|
||||
|
||||
redraw_display_if_reqd()
|
||||
|
||||
# update the display
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
time.sleep(0.01)
|
||||
|
|
|
@ -10,7 +10,7 @@ super computer doing its work in the eighties.
|
|||
You can adjust the brightness with LUX + and -.
|
||||
'''
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
cu = CosmicUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
|
||||
colour = (230, 150, 0)
|
||||
|
@ -42,7 +42,7 @@ def draw():
|
|||
graphics.set_pen(0)
|
||||
graphics.pixel(x, y)
|
||||
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
|
||||
@micropython.native # noqa: F821
|
||||
|
@ -58,15 +58,15 @@ def update():
|
|||
|
||||
setup()
|
||||
|
||||
gu.set_brightness(0.5)
|
||||
cu.set_brightness(0.5)
|
||||
|
||||
while True:
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
start = time.ticks_ms()
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ Displays some text, gradients and colours and demonstrates button use.
|
|||
You can adjust the brightness with LUX + and -.
|
||||
'''
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
cu = CosmicUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
|
||||
width = CosmicUnicorn.WIDTH
|
||||
|
@ -57,18 +57,18 @@ def outline_text(text):
|
|||
graphics.text(text, x, y, -1, 1)
|
||||
|
||||
|
||||
gu.set_brightness(0.5)
|
||||
cu.set_brightness(0.5)
|
||||
|
||||
while True:
|
||||
|
||||
time_ms = time.ticks_ms()
|
||||
test = (time_ms // 1000) % 5
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
graphics.set_pen(graphics.create_pen(0, 0, 0))
|
||||
graphics.clear()
|
||||
|
@ -91,33 +91,33 @@ while True:
|
|||
|
||||
text = ""
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_A):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_A):
|
||||
text = "Button A"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_B):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_B):
|
||||
text = "Button B"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_C):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_C):
|
||||
text = "Button C"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_D):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_D):
|
||||
text = "Button D"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP):
|
||||
text = "Louder!"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN):
|
||||
text = "Quieter"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
text = "Brighter!"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
text = "Darker"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_SLEEP):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_SLEEP):
|
||||
text = "Zzz... zzz..."
|
||||
|
||||
outline_text(text)
|
||||
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
|
|
@ -18,7 +18,7 @@ Also demonstrates some of the audio / synth features.
|
|||
|
||||
gc.collect()
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
cu = CosmicUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
|
||||
width = CosmicUnicorn.WIDTH
|
||||
|
@ -56,7 +56,7 @@ bass_notes = (
|
|||
SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, SUB, -1, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, SUB, -1, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, SUB, -1, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, SUB, -1, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0)
|
||||
|
||||
notes = [melody_notes, rhythm_notes, drum_beats, hi_hat, bass_notes]
|
||||
channels = [gu.synth_channel(i) for i in range(len(notes) + 1)] # Extra channel for tones
|
||||
channels = [cu.synth_channel(i) for i in range(len(notes) + 1)] # Extra channel for tones
|
||||
|
||||
# Configure the synth to play our notes
|
||||
channels[0].configure(waveforms=Channel.TRIANGLE + Channel.SQUARE,
|
||||
|
@ -136,7 +136,7 @@ def outline_text(text):
|
|||
graphics.text(text, x, y, -1, 1)
|
||||
|
||||
|
||||
gu.set_brightness(0.5)
|
||||
cu.set_brightness(0.5)
|
||||
|
||||
# Vars for storing button state
|
||||
was_a_pressed = False
|
||||
|
@ -181,7 +181,7 @@ while True:
|
|||
time_ms = time.ticks_ms()
|
||||
test = (time_ms // 1000) % 5
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_A):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_A):
|
||||
if not was_a_pressed:
|
||||
channels[0].volume(10000 / 65535)
|
||||
channels[1].volume(12000 / 65535)
|
||||
|
@ -195,7 +195,7 @@ while True:
|
|||
beat = 0
|
||||
next_beat()
|
||||
|
||||
gu.play_synth()
|
||||
cu.play_synth()
|
||||
synthing = True
|
||||
timer.init(freq=10, mode=Timer.PERIODIC, callback=tick)
|
||||
|
||||
|
@ -203,7 +203,7 @@ while True:
|
|||
else:
|
||||
was_a_pressed = False
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_B):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_B):
|
||||
if not was_b_pressed:
|
||||
channels[0].volume(0)
|
||||
channels[1].volume(12000 / 65535)
|
||||
|
@ -217,7 +217,7 @@ while True:
|
|||
beat = 0
|
||||
next_beat()
|
||||
|
||||
gu.play_synth()
|
||||
cu.play_synth()
|
||||
synthing = True
|
||||
timer.init(freq=10, mode=Timer.PERIODIC, callback=tick)
|
||||
|
||||
|
@ -225,7 +225,7 @@ while True:
|
|||
else:
|
||||
was_b_pressed = False
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_C):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_C):
|
||||
if not was_c_pressed:
|
||||
# Stop synth (if running) and play Tone A
|
||||
timer.deinit()
|
||||
|
@ -233,14 +233,14 @@ while True:
|
|||
channels[5].play_tone(tone_a, 0.06)
|
||||
channels[5].volume(12000 / 65535)
|
||||
|
||||
gu.play_synth()
|
||||
cu.play_synth()
|
||||
synthing = False
|
||||
|
||||
was_c_pressed = True
|
||||
else:
|
||||
was_c_pressed = False
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_D):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_D):
|
||||
if not was_d_pressed:
|
||||
# Stop synth (if running) and play Tone B
|
||||
timer.deinit()
|
||||
|
@ -249,43 +249,43 @@ while True:
|
|||
channels[5].play_tone(tone_b, 0.06, attack=0.5)
|
||||
channels[5].volume(12000 / 65535)
|
||||
|
||||
gu.play_synth()
|
||||
cu.play_synth()
|
||||
synthing = False
|
||||
|
||||
was_d_pressed = True
|
||||
else:
|
||||
was_d_pressed = False
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
if tone_b > 0: # Zero means tone not playing
|
||||
# Increase Tone B
|
||||
tone_b = min(tone_b + 10, 20000)
|
||||
channels[5].frequency(tone_b)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
if tone_b > 0: # Zero means tone not playing
|
||||
# Decrease Tone B
|
||||
tone_b = max(tone_b - 10, 10)
|
||||
channels[5].frequency(max(tone_b, 10))
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP):
|
||||
if tone_a > 0: # Zero means tone not playing
|
||||
# Increase Tone A
|
||||
tone_a = min(tone_a + 10, 20000)
|
||||
channels[5].frequency(tone_a)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN):
|
||||
if tone_a > 0: # Zero means tone not playing
|
||||
# Decrease Tone A
|
||||
tone_a = max(tone_a - 10, 10)
|
||||
channels[5].frequency(tone_a)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_SLEEP):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_SLEEP):
|
||||
if not was_z_pressed:
|
||||
# Stop synth and both tones
|
||||
tone_a = 0
|
||||
tone_b = 0
|
||||
gu.stop_playing()
|
||||
cu.stop_playing()
|
||||
timer.deinit()
|
||||
synthing = False
|
||||
|
||||
|
@ -312,36 +312,36 @@ while True:
|
|||
# print("white gradient")
|
||||
gradient(255, 255, 255)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_A):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_A):
|
||||
text = "PlaySyn"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_B):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_B):
|
||||
text = "SoloSyn"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_C):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_C):
|
||||
text = "Tone A"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_D):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_D):
|
||||
text = "Tone B"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP):
|
||||
text = "RaiseA"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN):
|
||||
text = "LowerA"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
text = "RaiseB"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
text = "LowerB"
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_SLEEP):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_SLEEP):
|
||||
text = "Stop"
|
||||
|
||||
outline_text(text)
|
||||
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
# pause for a moment (important or the USB serial device will fail
|
||||
time.sleep(0.001)
|
||||
|
|
|
@ -9,7 +9,7 @@ A pretty, procedural fire effect.
|
|||
You can adjust the brightness with LUX + and -.
|
||||
'''
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
cu = CosmicUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
|
||||
fire_colours = [graphics.create_pen(0, 0, 0),
|
||||
|
@ -71,7 +71,7 @@ def draw():
|
|||
_set_pen(_fire_colours[4])
|
||||
_pixel(x, y)
|
||||
|
||||
gu.update(_graphics)
|
||||
cu.update(_graphics)
|
||||
|
||||
|
||||
width = CosmicUnicorn.WIDTH + 2
|
||||
|
@ -81,15 +81,15 @@ fire_spawns = 5
|
|||
damping_factor = 0.97
|
||||
|
||||
|
||||
gu.set_brightness(0.5)
|
||||
cu.set_brightness(0.5)
|
||||
|
||||
while True:
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
start = time.ticks_ms()
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ A 70s-tastic, procedural rainbow lava lamp.
|
|||
You can adjust the brightness with LUX + and -.
|
||||
'''
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
cu = CosmicUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
|
||||
blob_count = 10
|
||||
|
@ -121,22 +121,22 @@ def draw_portrait():
|
|||
graphics.set_pen(0)
|
||||
graphics.pixel(y, x)
|
||||
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
|
||||
setup_portrait()
|
||||
|
||||
gu.set_brightness(0.5)
|
||||
cu.set_brightness(0.5)
|
||||
|
||||
while True:
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_A):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_A):
|
||||
setup_portrait()
|
||||
|
||||
start = time.ticks_ms()
|
||||
|
|
|
@ -9,7 +9,7 @@ pixel by pixel from a pattern of Os and Xs.
|
|||
You can adjust the brightness with LUX + and -.
|
||||
'''
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
cu = CosmicUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
|
||||
prompt_x = 0
|
||||
|
@ -125,21 +125,21 @@ def draw(image, fg, bg, time_ms):
|
|||
|
||||
graphics.pixel(x + prompt_x, y + prompt_y)
|
||||
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
|
||||
gu.set_brightness(0.5)
|
||||
cu.set_brightness(0.5)
|
||||
|
||||
while True:
|
||||
|
||||
time_ms = time.ticks_ms()
|
||||
prompt = (time_ms // 3000) % 3
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
start = time.ticks_ms()
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ Play with the number of spawns, heat, damping factor and colour palette to tweak
|
|||
# MAXIMUM OVERKILL
|
||||
# machine.freq(250_000_000)
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
gu.set_brightness(0.5)
|
||||
cu = CosmicUnicorn()
|
||||
cu.set_brightness(0.5)
|
||||
graphics = PicoGraphics(DISPLAY_COSMIC_UNICORN, pen_type=PEN_P8)
|
||||
|
||||
# Number of random fire spawns
|
||||
|
@ -79,7 +79,7 @@ def draw():
|
|||
# Multiplies it by the number of palette entries (-1) to turn it into a palette index
|
||||
# Converts to uint8_t datatype to match the framebuffer
|
||||
memoryview(graphics)[:] = numpy.ndarray(numpy.clip(heat[0:32, 0:32], 0, 1) * (PALETTE_SIZE - 1), dtype=numpy.uint8).tobytes()
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
|
||||
width = CosmicUnicorn.WIDTH
|
||||
|
@ -92,11 +92,11 @@ t_total = 0
|
|||
while True:
|
||||
gc.collect()
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
tstart = time.ticks_ms()
|
||||
gc.collect()
|
||||
|
|
|
@ -13,9 +13,9 @@ A lava lamp effect, created by blurred, moving particles.
|
|||
# MAXIMUM OVERKILL
|
||||
# machine.freq(250_000_000)
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
cu = CosmicUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY_COSMIC_UNICORN, pen_type=PEN_P8)
|
||||
gu.set_brightness(0.5)
|
||||
cu.set_brightness(0.5)
|
||||
|
||||
width = CosmicUnicorn.WIDTH
|
||||
height = CosmicUnicorn.HEIGHT
|
||||
|
@ -77,18 +77,18 @@ def draw():
|
|||
# Multiplies by palette entries (-1) to turn it into a palette index
|
||||
# Converts to uint8_t datatype to match the framebuffer
|
||||
memoryview(graphics)[:] = numpy.ndarray(numpy.clip(lava, 0.0, 1.0) * (PAL_COLS - 1), dtype=numpy.uint8).tobytes()
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
|
||||
t_count = 0
|
||||
t_total = 0
|
||||
|
||||
while True:
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
tstart = time.ticks_ms()
|
||||
gc.collect()
|
||||
|
|
|
@ -12,8 +12,8 @@ HELLO NEO.
|
|||
# MAXIMUM OVERKILL
|
||||
# machine.freq(250_000_000)
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
gu.set_brightness(1.0)
|
||||
cu = CosmicUnicorn()
|
||||
cu.set_brightness(1.0)
|
||||
graphics = PicoGraphics(DISPLAY_COSMIC_UNICORN, pen_type=PEN_P8)
|
||||
|
||||
|
||||
|
@ -43,7 +43,7 @@ def update():
|
|||
def draw():
|
||||
# Copy the effect to the framebuffer
|
||||
memoryview(graphics)[:] = numpy.ndarray(numpy.clip(trippy, 0, 1) * 254, dtype=numpy.uint8).tobytes()
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
|
||||
width = CosmicUnicorn.WIDTH
|
||||
|
@ -55,11 +55,11 @@ t_total = 0
|
|||
|
||||
|
||||
while True:
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
tstart = time.ticks_ms()
|
||||
gc.collect()
|
||||
|
|
|
@ -12,8 +12,8 @@ THIS IS FINE!
|
|||
# MAXIMUM OVERKILL
|
||||
# machine.freq(250_000_000)
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
gu.set_brightness(0.5)
|
||||
cu = CosmicUnicorn()
|
||||
cu.set_brightness(0.5)
|
||||
graphics = PicoGraphics(DISPLAY_COSMIC_UNICORN, pen_type=PEN_P8)
|
||||
|
||||
# Number of random fire spawns
|
||||
|
@ -84,7 +84,7 @@ def draw():
|
|||
graphics.text("This", 6, 4, 1, 1)
|
||||
graphics.text("is", 11, 12, 1, 1)
|
||||
graphics.text("fine", 6, 20, 1, 1)
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
|
||||
width = CosmicUnicorn.WIDTH
|
||||
|
@ -97,11 +97,11 @@ t_total = 0
|
|||
while True:
|
||||
gc.collect()
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
tstart = time.ticks_ms()
|
||||
gc.collect()
|
||||
|
|
|
@ -13,8 +13,8 @@ Experiment with the damping, number of spawns, intensity and offset to change th
|
|||
# MAXIMUM OVERKILL
|
||||
# machine.freq(250_000_000)
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
gu.set_brightness(0.5)
|
||||
cu = CosmicUnicorn()
|
||||
cu.set_brightness(0.5)
|
||||
graphics = PicoGraphics(DISPLAY_COSMIC_UNICORN, pen_type=PEN_P8)
|
||||
|
||||
|
||||
|
@ -51,7 +51,7 @@ def update():
|
|||
def draw():
|
||||
# Copy the effect to the framebuffer
|
||||
memoryview(graphics)[:] = numpy.ndarray(numpy.clip(trippy, 0, 1) * (PALETTE_ENTRIES - 1), dtype=numpy.uint8).tobytes()
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
|
||||
width = CosmicUnicorn.WIDTH
|
||||
|
@ -63,11 +63,11 @@ t_total = 0
|
|||
|
||||
|
||||
while True:
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
tstart = time.ticks_ms()
|
||||
gc.collect()
|
||||
|
|
|
@ -12,7 +12,7 @@ and the brightness with LUX + and -.
|
|||
The sleep button stops the animation (can be started again with A or B).
|
||||
'''
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
cu = CosmicUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
|
||||
width = CosmicUnicorn.WIDTH
|
||||
|
@ -55,7 +55,7 @@ def draw():
|
|||
graphics.set_pen(graphics.create_pen(int(colour[0] * v), int(colour[1] * v), int(colour[2] * v)))
|
||||
graphics.pixel(x, y)
|
||||
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
|
||||
hue_map = [from_hsv(x / width, 1.0, 1.0) for x in range(width)]
|
||||
|
@ -65,7 +65,7 @@ animate = True
|
|||
stripe_width = 3.0
|
||||
speed = 1.0
|
||||
|
||||
gu.set_brightness(0.5)
|
||||
cu.set_brightness(0.5)
|
||||
|
||||
phase = 0
|
||||
while True:
|
||||
|
@ -73,38 +73,38 @@ while True:
|
|||
if animate:
|
||||
phase += speed
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP):
|
||||
hue_offset += 0.01
|
||||
hue_offset = 1.0 if hue_offset > 1.0 else hue_offset
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN):
|
||||
hue_offset -= 0.01
|
||||
hue_offset = 0.0 if hue_offset < 0.0 else hue_offset
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_SLEEP):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_SLEEP):
|
||||
animate = False
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_A):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_A):
|
||||
speed += 0.05
|
||||
speed = 10.0 if speed > 10.0 else speed
|
||||
animate = True
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_B):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_B):
|
||||
speed -= 0.05
|
||||
speed = 0.0 if speed < 0.0 else speed
|
||||
animate = True
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_C):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_C):
|
||||
stripe_width += 0.05
|
||||
stripe_width = 10.0 if stripe_width > 10.0 else stripe_width
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_D):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_D):
|
||||
stripe_width -= 0.05
|
||||
stripe_width = 1.0 if stripe_width < 1.0 else stripe_width
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ HOLD_TIME = 2.0
|
|||
STEP_TIME = 0.075
|
||||
|
||||
# create cosmic object and graphics surface for drawing
|
||||
gu = CosmicUnicorn()
|
||||
cu = CosmicUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
|
||||
width = CosmicUnicorn.WIDTH
|
||||
|
@ -41,7 +41,7 @@ def outline_text(text, x, y):
|
|||
graphics.text(text, x, y, -1, 1)
|
||||
|
||||
|
||||
gu.set_brightness(0.5)
|
||||
cu.set_brightness(0.5)
|
||||
|
||||
# state constants
|
||||
STATE_PRE_SCROLL = 0
|
||||
|
@ -62,11 +62,11 @@ last_time = time.ticks_ms()
|
|||
while True:
|
||||
time_ms = time.ticks_ms()
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
if state == STATE_PRE_SCROLL and time_ms - last_time > HOLD_TIME * 1000:
|
||||
if msg_width + PADDING * 2 >= width:
|
||||
|
@ -90,7 +90,7 @@ while True:
|
|||
outline_text(MESSAGE, x=PADDING - shift, y=2)
|
||||
|
||||
# update the display
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
# pause for a moment (important or the USB serial device will fail)
|
||||
time.sleep(0.001)
|
||||
|
|
|
@ -6,11 +6,11 @@ import machine
|
|||
from cosmic import CosmicUnicorn
|
||||
from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY
|
||||
|
||||
gu = CosmicUnicorn()
|
||||
cu = CosmicUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
|
||||
# Default Brightness
|
||||
gu.set_brightness(0.4)
|
||||
cu.set_brightness(0.4)
|
||||
|
||||
# You will need to create or update the file secrets.py with your network credentials using Thonny
|
||||
# in order for the example to update using the NTP.
|
||||
|
@ -106,7 +106,7 @@ def draw():
|
|||
|
||||
graphics.set_pen(graphics.create_pen(0, 0, 0))
|
||||
|
||||
gu.update(graphics)
|
||||
cu.update(graphics)
|
||||
|
||||
|
||||
init()
|
||||
|
@ -114,14 +114,14 @@ init()
|
|||
while 1:
|
||||
|
||||
# Adjust Brightness +/-
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
|
||||
cu.adjust_brightness(+0.01)
|
||||
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
gu.adjust_brightness(-0.01)
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
|
||||
cu.adjust_brightness(-0.01)
|
||||
|
||||
# Connect to the network and sync with the NTP server
|
||||
if gu.is_pressed(CosmicUnicorn.SWITCH_C):
|
||||
if cu.is_pressed(CosmicUnicorn.SWITCH_C):
|
||||
sync_time()
|
||||
|
||||
draw()
|
||||
|
|
Ładowanie…
Reference in New Issue