kopia lustrzana https://github.com/pimoroni/pimoroni-pico
commit
d127f4d299
|
@ -0,0 +1,35 @@
|
|||
name: Python
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: ${{matrix.name}}
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
name: Linux
|
||||
cache-key: linux
|
||||
apt-packages: python3 python3-pip
|
||||
python-packages: flake8
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
# Linux deps
|
||||
- name: Install deps
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
sudo apt update && sudo apt install ${{matrix.apt-packages}}
|
||||
|
||||
- name: Install Python Deps
|
||||
run: python3 -m pip install ${{matrix.python-packages}}
|
||||
|
||||
- name: Lint
|
||||
shell: bash
|
||||
run: |
|
||||
python3 -m flake8 --ignore E501 micropython/examples
|
|
@ -1,4 +1,5 @@
|
|||
import time, random, math
|
||||
import time
|
||||
import math
|
||||
from breakout_roundlcd import BreakoutRoundLCD
|
||||
|
||||
width = BreakoutRoundLCD.WIDTH
|
||||
|
@ -11,10 +12,11 @@ display.set_backlight(1.0)
|
|||
|
||||
RADIUS = width // 2
|
||||
|
||||
|
||||
def hsv_to_rgb(h, s, v):
|
||||
if s == 0.0:
|
||||
return v, v, v
|
||||
i = int(h * 6.0) # XXX assume int() truncates!
|
||||
i = int(h * 6.0) # XXX assume int() truncates!
|
||||
f = (h * 6.0) - i
|
||||
p = v * (1.0 - s)
|
||||
q = v * (1.0 - s * f)
|
||||
|
@ -33,19 +35,21 @@ def hsv_to_rgb(h, s, v):
|
|||
if i == 5:
|
||||
return v, p, q
|
||||
|
||||
|
||||
t = 0
|
||||
|
||||
while True:
|
||||
display.set_pen(0, 0, 0)
|
||||
display.clear()
|
||||
|
||||
angle = t % (math.pi * 2)
|
||||
|
||||
|
||||
prev_x = RADIUS
|
||||
prev_y = RADIUS
|
||||
|
||||
steps = 30.0
|
||||
angle_step = 0.5
|
||||
|
||||
|
||||
for step in range(int(steps)):
|
||||
angle += angle_step
|
||||
|
||||
|
@ -57,13 +61,13 @@ while True:
|
|||
x = RADIUS + int(distance * math.cos(angle))
|
||||
y = RADIUS + int(distance * math.sin(angle))
|
||||
|
||||
l = ((math.sin(t + angle) + 1) / 2.0) * 10
|
||||
radius = ((math.sin(t + angle) + 1) / 2.0) * 10
|
||||
display.set_pen(r, g, b)
|
||||
display.circle(int(x), int(y), int(l))
|
||||
display.circle(int(x), int(y), int(radius))
|
||||
|
||||
prev_x = x
|
||||
prev_y = y
|
||||
|
||||
|
||||
display.update()
|
||||
time.sleep(0.02)
|
||||
t += 0.02
|
||||
t += 0.02
|
||||
|
|
|
@ -8,12 +8,14 @@ buf = bytearray(display.get_width() * display.get_height() * 2)
|
|||
display.init(buf)
|
||||
display.set_backlight(0.5)
|
||||
|
||||
|
||||
# sets up a handy function we can call to clear the screen
|
||||
def clear():
|
||||
def clear():
|
||||
display.set_pen(0, 0, 0)
|
||||
display.clear()
|
||||
display.update()
|
||||
|
||||
|
||||
|
||||
while True:
|
||||
if display.is_pressed(display.BUTTON_A): # if a button press is detected then...
|
||||
clear() # clear to black
|
||||
|
@ -44,8 +46,7 @@ while True:
|
|||
utime.sleep(1)
|
||||
clear()
|
||||
else:
|
||||
display.set_pen(255, 0, 0)
|
||||
display.set_pen(255, 0, 0)
|
||||
display.text("Press any button!", 10, 10, 240, 4)
|
||||
display.update()
|
||||
utime.sleep(0.1) # this number is how frequently the Pico checks for button presses
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import time, random
|
||||
import picodisplay as display
|
||||
import time
|
||||
import random
|
||||
import picodisplay as display
|
||||
|
||||
width = display.get_width()
|
||||
height = display.get_height()
|
||||
|
@ -19,6 +20,7 @@ class Ball:
|
|||
self.dy = dy
|
||||
self.pen = pen
|
||||
|
||||
|
||||
# initialise shapes
|
||||
balls = []
|
||||
for i in range(0, 100):
|
||||
|
@ -30,18 +32,18 @@ for i in range(0, 100):
|
|||
r,
|
||||
(14 - r) / 2,
|
||||
(14 - r) / 2,
|
||||
display.create_pen(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
|
||||
display.create_pen(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
while True:
|
||||
display.set_pen(40, 40, 40)
|
||||
display.clear()
|
||||
|
||||
|
||||
for ball in balls:
|
||||
ball.x += ball.dx
|
||||
ball.y += ball.dy
|
||||
|
||||
|
||||
xmax = width - ball.r
|
||||
xmin = ball.r
|
||||
ymax = height - ball.r
|
||||
|
@ -55,6 +57,6 @@ while True:
|
|||
|
||||
display.set_pen(ball.pen)
|
||||
display.circle(int(ball.x), int(ball.y), int(ball.r))
|
||||
|
||||
|
||||
display.update()
|
||||
time.sleep(0.01)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
## This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Display's screen and RGB LED . If you're into rainbows, HSV (Hue, Saturation, Value) is very useful!
|
||||
# This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Display's screen and RGB LED . If you're into rainbows, HSV (Hue, Saturation, Value) is very useful!
|
||||
|
||||
import utime
|
||||
import picodisplay as display
|
||||
|
@ -8,16 +8,17 @@ buf = bytearray(display.get_width() * display.get_height() * 2)
|
|||
display.init(buf)
|
||||
display.set_backlight(0.8)
|
||||
|
||||
|
||||
# From CPython Lib/colorsys.py
|
||||
def hsv_to_rgb(h, s, v):
|
||||
if s == 0.0:
|
||||
return v, v, v
|
||||
i = int(h*6.0)
|
||||
f = (h*6.0) - i
|
||||
p = v*(1.0 - s)
|
||||
q = v*(1.0 - s*f)
|
||||
t = v*(1.0 - s*(1.0-f))
|
||||
i = i%6
|
||||
i = int(h * 6.0)
|
||||
f = (h * 6.0) - i
|
||||
p = v * (1.0 - s)
|
||||
q = v * (1.0 - s * f)
|
||||
t = v * (1.0 - s * (1.0 - f))
|
||||
i = i % 6
|
||||
if i == 0:
|
||||
return v, t, p
|
||||
if i == 1:
|
||||
|
@ -31,6 +32,7 @@ def hsv_to_rgb(h, s, v):
|
|||
if i == 5:
|
||||
return v, p, q
|
||||
|
||||
|
||||
h = 0
|
||||
|
||||
while True:
|
||||
|
@ -42,4 +44,4 @@ while True:
|
|||
display.set_pen(0, 0, 0) # Set pen to black
|
||||
display.text("pico disco!", 10, 10, 240, 6) # Add some text
|
||||
display.update() # Update the display
|
||||
utime.sleep(1.0 / 60)
|
||||
utime.sleep(1.0 / 60)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# This example takes the temperature from the Pico's onboard temperature sensor, and displays it on Pico Display Pack, along with a little pixelly graph.
|
||||
# It's based on the thermometer example in the "Getting Started with MicroPython on the Raspberry Pi Pico" book, which is a great read if you're a beginner!
|
||||
|
||||
import machine
|
||||
import machine
|
||||
import utime
|
||||
import gc
|
||||
|
||||
|
@ -14,7 +14,7 @@ display_buffer = bytearray(width * height * 2)
|
|||
display.init(display_buffer)
|
||||
|
||||
# reads from Pico's temp sensor and converts it into a more manageable number
|
||||
sensor_temp = machine.ADC(4)
|
||||
sensor_temp = machine.ADC(4)
|
||||
conversion_factor = 3.3 / (65535)
|
||||
temp_min = 10
|
||||
temp_max = 30
|
||||
|
@ -56,7 +56,7 @@ while True:
|
|||
# the following two lines do some maths to convert the number from the temp sensor into celsius
|
||||
reading = sensor_temp.read_u16() * conversion_factor
|
||||
temperature = 27 - (reading - 0.706) / 0.001721
|
||||
|
||||
|
||||
temperatures.append(temperature)
|
||||
|
||||
# shifts the temperatures history to the left by one sample
|
||||
|
@ -67,27 +67,27 @@ while True:
|
|||
for t in temperatures:
|
||||
# chooses a pen colour based on the temperature
|
||||
display.set_pen(*temperature_to_color(t))
|
||||
|
||||
|
||||
# draws the reading as a tall, thin rectangle
|
||||
display.rectangle(i, height - (round(t) * 4), bar_width, height)
|
||||
|
||||
# the next tall thin rectangle needs to be drawn
|
||||
# "bar_width" (default: 5) pixels to the right of the last one
|
||||
i += bar_width
|
||||
|
||||
|
||||
# heck lets also set the LED to match
|
||||
display.set_led(*temperature_to_color(temperature))
|
||||
|
||||
# draws a white background for the text
|
||||
display.set_pen(255, 255, 255)
|
||||
display.rectangle(1, 1, 100, 25)
|
||||
|
||||
|
||||
# writes the reading as text in the white rectangle
|
||||
display.set_pen(0, 0, 0)
|
||||
display.text("{:.2f}".format(temperature) + "c", 3, 3, 0, 3)
|
||||
|
||||
|
||||
# time to update the display
|
||||
display.update()
|
||||
|
||||
|
||||
# waits for 5 seconds
|
||||
utime.sleep(5)
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
# adapted from demo.py in examples/pico_display
|
||||
# runs full screen on a pico explorer
|
||||
# all credit to orignal author(s) -
|
||||
# all credit to orignal author(s) -
|
||||
# I just changed the import statement to import picoexplorer instaead of picodisplay
|
||||
|
||||
|
||||
import time, random
|
||||
import picoexplorer as display
|
||||
import time
|
||||
import random
|
||||
import picoexplorer as display
|
||||
|
||||
width = display.get_width()
|
||||
height = display.get_height()
|
||||
|
@ -25,6 +26,7 @@ class Ball:
|
|||
self.dy = dy
|
||||
self.pen = pen
|
||||
|
||||
|
||||
# initialise shapes
|
||||
balls = []
|
||||
for i in range(0, 100):
|
||||
|
@ -36,18 +38,18 @@ for i in range(0, 100):
|
|||
r,
|
||||
(14 - r) / 2,
|
||||
(14 - r) / 2,
|
||||
display.create_pen(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
|
||||
display.create_pen(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
while True:
|
||||
display.set_pen(40, 40, 40)
|
||||
display.clear()
|
||||
|
||||
|
||||
for ball in balls:
|
||||
ball.x += ball.dx
|
||||
ball.y += ball.dy
|
||||
|
||||
|
||||
xmax = width - ball.r
|
||||
xmin = ball.r
|
||||
ymax = height - ball.r
|
||||
|
@ -61,6 +63,7 @@ while True:
|
|||
|
||||
display.set_pen(ball.pen)
|
||||
display.circle(int(ball.x), int(ball.y), int(ball.r))
|
||||
|
||||
|
||||
display.update()
|
||||
|
||||
time.sleep(0.01)
|
||||
|
|
|
@ -7,12 +7,14 @@ import utime
|
|||
buf = bytearray(display.get_width() * display.get_height() * 2)
|
||||
display.init(buf)
|
||||
|
||||
|
||||
# sets up a handy function we can call to clear the screen
|
||||
def clear():
|
||||
def clear():
|
||||
display.set_pen(0, 0, 0)
|
||||
display.clear()
|
||||
display.update()
|
||||
|
||||
|
||||
|
||||
while True:
|
||||
if display.is_pressed(display.BUTTON_A): # if a button press is detected then...
|
||||
clear() # clear to black
|
||||
|
@ -43,8 +45,7 @@ while True:
|
|||
utime.sleep(1)
|
||||
clear()
|
||||
else:
|
||||
display.set_pen(255, 0, 0)
|
||||
display.set_pen(255, 0, 0)
|
||||
display.text("Press any button!", 10, 10, 240, 4)
|
||||
display.update()
|
||||
utime.sleep(0.1) # this number is how frequently the Pico checks for button presses
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import time, random
|
||||
import time
|
||||
import picoexplorer as explorer
|
||||
|
||||
width = explorer.get_width()
|
||||
|
@ -12,26 +12,26 @@ explorer.set_audio_pin(0)
|
|||
i = 1
|
||||
|
||||
while True:
|
||||
explorer.set_pen(120, 40, 60)
|
||||
explorer.set_pen(120, 40, 60)
|
||||
explorer.clear()
|
||||
|
||||
|
||||
adc0 = int(explorer.get_adc(0) * 120)
|
||||
adc1 = int(explorer.get_adc(1) * 120)
|
||||
adc2 = int(explorer.get_adc(2) * 120)
|
||||
|
||||
|
||||
explorer.set_pen(255, 255, 255)
|
||||
|
||||
explorer.text("ADC0:", 20, 20, 100)
|
||||
explorer.text("ADC1:", 20, 40, 100)
|
||||
explorer.text("ADC2:", 20, 60, 100)
|
||||
explorer.text("ADC0:", 20, 20, 100)
|
||||
explorer.text("ADC1:", 20, 40, 100)
|
||||
explorer.text("ADC2:", 20, 60, 100)
|
||||
|
||||
explorer.set_pen(adc0 * 2, 0, 0)
|
||||
explorer.set_pen(adc0 * 2, 0, 0)
|
||||
explorer.circle(90 + adc0, 26, 10)
|
||||
|
||||
explorer.set_pen(0, adc1 * 2, 0)
|
||||
|
||||
explorer.set_pen(0, adc1 * 2, 0)
|
||||
explorer.circle(90 + adc1, 46, 10)
|
||||
|
||||
explorer.set_pen(0, 0, adc2 * 2)
|
||||
explorer.set_pen(0, 0, adc2 * 2)
|
||||
explorer.circle(90 + adc2, 66, 10)
|
||||
|
||||
# example for the on-board A/B/X/Y buttons
|
||||
|
@ -53,27 +53,27 @@ while True:
|
|||
else:
|
||||
# no button press was detected
|
||||
explorer.set_pen(255, 255, 255)
|
||||
explorer.text("Plug a jumper wire from GP0 to AUDIO to hear noise!", 20, 110, 200)
|
||||
explorer.text("Plug a jumper wire from GP0 to AUDIO to hear noise!", 20, 110, 200)
|
||||
|
||||
explorer.set_tone(i)
|
||||
|
||||
if i > 600:
|
||||
explorer.text("Motor 1: Forwards", 20, 180, 200)
|
||||
if i > 600:
|
||||
explorer.text("Motor 1: Forwards", 20, 180, 200)
|
||||
explorer.set_motor(0, 0, 1)
|
||||
else:
|
||||
explorer.text("Motor 1: Backwards", 20, 180, 200)
|
||||
explorer.text("Motor 1: Backwards", 20, 180, 200)
|
||||
explorer.set_motor(0, 1, 1)
|
||||
|
||||
|
||||
if i > 600:
|
||||
explorer.text("Motor 2: Forwards", 20, 200, 200)
|
||||
explorer.text("Motor 2: Forwards", 20, 200, 200)
|
||||
explorer.set_motor(1, 0, 1)
|
||||
else:
|
||||
explorer.text("Motor 2: Backwards", 20, 200, 200)
|
||||
explorer.text("Motor 2: Backwards", 20, 200, 200)
|
||||
explorer.set_motor(1, 1, 1)
|
||||
|
||||
i = i + 20
|
||||
if i > 1000:
|
||||
i = 1
|
||||
|
||||
|
||||
explorer.update()
|
||||
time.sleep(0.01)
|
||||
|
|
|
@ -14,111 +14,115 @@ explorer.set_audio_pin(0)
|
|||
|
||||
# this handy list converts notes into frequencies, which you can use with the explorer.set_tone function
|
||||
tones = {
|
||||
"B0": 31,
|
||||
"C1": 33,
|
||||
"CS1": 35,
|
||||
"D1": 37,
|
||||
"DS1": 39,
|
||||
"E1": 41,
|
||||
"F1": 44,
|
||||
"FS1": 46,
|
||||
"G1": 49,
|
||||
"GS1": 52,
|
||||
"A1": 55,
|
||||
"AS1": 58,
|
||||
"B1": 62,
|
||||
"C2": 65,
|
||||
"CS2": 69,
|
||||
"D2": 73,
|
||||
"DS2": 78,
|
||||
"E2": 82,
|
||||
"F2": 87,
|
||||
"FS2": 93,
|
||||
"G2": 98,
|
||||
"GS2": 104,
|
||||
"A2": 110,
|
||||
"AS2": 117,
|
||||
"B2": 123,
|
||||
"C3": 131,
|
||||
"CS3": 139,
|
||||
"D3": 147,
|
||||
"DS3": 156,
|
||||
"E3": 165,
|
||||
"F3": 175,
|
||||
"FS3": 185,
|
||||
"G3": 196,
|
||||
"GS3": 208,
|
||||
"A3": 220,
|
||||
"AS3": 233,
|
||||
"B3": 247,
|
||||
"C4": 262,
|
||||
"CS4": 277,
|
||||
"D4": 294,
|
||||
"DS4": 311,
|
||||
"E4": 330,
|
||||
"F4": 349,
|
||||
"FS4": 370,
|
||||
"G4": 392,
|
||||
"GS4": 415,
|
||||
"A4": 440,
|
||||
"AS4": 466,
|
||||
"B4": 494,
|
||||
"C5": 523,
|
||||
"CS5": 554,
|
||||
"D5": 587,
|
||||
"DS5": 622,
|
||||
"E5": 659,
|
||||
"F5": 698,
|
||||
"FS5": 740,
|
||||
"G5": 784,
|
||||
"GS5": 831,
|
||||
"A5": 880,
|
||||
"AS5": 932,
|
||||
"B5": 988,
|
||||
"C6": 1047,
|
||||
"CS6": 1109,
|
||||
"D6": 1175,
|
||||
"DS6": 1245,
|
||||
"E6": 1319,
|
||||
"F6": 1397,
|
||||
"FS6": 1480,
|
||||
"G6": 1568,
|
||||
"GS6": 1661,
|
||||
"A6": 1760,
|
||||
"AS6": 1865,
|
||||
"B6": 1976,
|
||||
"C7": 2093,
|
||||
"CS7": 2217,
|
||||
"D7": 2349,
|
||||
"DS7": 2489,
|
||||
"E7": 2637,
|
||||
"F7": 2794,
|
||||
"FS7": 2960,
|
||||
"G7": 3136,
|
||||
"GS7": 3322,
|
||||
"A7": 3520,
|
||||
"AS7": 3729,
|
||||
"B7": 3951,
|
||||
"C8": 4186,
|
||||
"CS8": 4435,
|
||||
"D8": 4699,
|
||||
"DS8": 4978
|
||||
"B0": 31,
|
||||
"C1": 33,
|
||||
"CS1": 35,
|
||||
"D1": 37,
|
||||
"DS1": 39,
|
||||
"E1": 41,
|
||||
"F1": 44,
|
||||
"FS1": 46,
|
||||
"G1": 49,
|
||||
"GS1": 52,
|
||||
"A1": 55,
|
||||
"AS1": 58,
|
||||
"B1": 62,
|
||||
"C2": 65,
|
||||
"CS2": 69,
|
||||
"D2": 73,
|
||||
"DS2": 78,
|
||||
"E2": 82,
|
||||
"F2": 87,
|
||||
"FS2": 93,
|
||||
"G2": 98,
|
||||
"GS2": 104,
|
||||
"A2": 110,
|
||||
"AS2": 117,
|
||||
"B2": 123,
|
||||
"C3": 131,
|
||||
"CS3": 139,
|
||||
"D3": 147,
|
||||
"DS3": 156,
|
||||
"E3": 165,
|
||||
"F3": 175,
|
||||
"FS3": 185,
|
||||
"G3": 196,
|
||||
"GS3": 208,
|
||||
"A3": 220,
|
||||
"AS3": 233,
|
||||
"B3": 247,
|
||||
"C4": 262,
|
||||
"CS4": 277,
|
||||
"D4": 294,
|
||||
"DS4": 311,
|
||||
"E4": 330,
|
||||
"F4": 349,
|
||||
"FS4": 370,
|
||||
"G4": 392,
|
||||
"GS4": 415,
|
||||
"A4": 440,
|
||||
"AS4": 466,
|
||||
"B4": 494,
|
||||
"C5": 523,
|
||||
"CS5": 554,
|
||||
"D5": 587,
|
||||
"DS5": 622,
|
||||
"E5": 659,
|
||||
"F5": 698,
|
||||
"FS5": 740,
|
||||
"G5": 784,
|
||||
"GS5": 831,
|
||||
"A5": 880,
|
||||
"AS5": 932,
|
||||
"B5": 988,
|
||||
"C6": 1047,
|
||||
"CS6": 1109,
|
||||
"D6": 1175,
|
||||
"DS6": 1245,
|
||||
"E6": 1319,
|
||||
"F6": 1397,
|
||||
"FS6": 1480,
|
||||
"G6": 1568,
|
||||
"GS6": 1661,
|
||||
"A6": 1760,
|
||||
"AS6": 1865,
|
||||
"B6": 1976,
|
||||
"C7": 2093,
|
||||
"CS7": 2217,
|
||||
"D7": 2349,
|
||||
"DS7": 2489,
|
||||
"E7": 2637,
|
||||
"F7": 2794,
|
||||
"FS7": 2960,
|
||||
"G7": 3136,
|
||||
"GS7": 3322,
|
||||
"A7": 3520,
|
||||
"AS7": 3729,
|
||||
"B7": 3951,
|
||||
"C8": 4186,
|
||||
"CS8": 4435,
|
||||
"D8": 4699,
|
||||
"DS8": 4978
|
||||
}
|
||||
|
||||
# put the notes for your song in here!
|
||||
song = ["F6","F6","E6","F6","F5","P","F5","P","C6","AS5","A5","C6","F6","P","F6","P","G6","FS6","G6","G5","P","G5","P","G6","F6","E6","D6","C6","P","C6","P","D6","E6","F6","E6","D6","C6","D6","C6","AS5","A5","AS5","A5","G5","F5","G5","F5","E5","D5","C5","D5","E5","F5","G5","AS5","A5","G5","A5","F5","P","F5"]
|
||||
song = ["F6", "F6", "E6", "F6", "F5", "P", "F5", "P", "C6", "AS5", "A5", "C6", "F6", "P", "F6", "P", "G6", "FS6", "G6", "G5", "P", "G5", "P", "G6", "F6", "E6", "D6", "C6", "P", "C6", "P", "D6", "E6", "F6", "E6", "D6", "C6", "D6", "C6", "AS5", "A5", "AS5", "A5", "G5", "F5", "G5", "F5", "E5", "D5", "C5", "D5", "E5", "F5", "G5", "AS5", "A5", "G5", "A5", "F5", "P", "F5"]
|
||||
|
||||
|
||||
def clear(): # this function clears Pico Explorer's screen to black
|
||||
explorer.set_pen(0,0,0)
|
||||
explorer.set_pen(0, 0, 0)
|
||||
explorer.clear()
|
||||
explorer.update()
|
||||
|
||||
|
||||
|
||||
def playtone(frequency): # this function tells your program how to make noise
|
||||
explorer.set_tone(frequency)
|
||||
|
||||
|
||||
def bequiet(): # this function tells your program how not to make noise
|
||||
explorer.set_tone(-1)
|
||||
|
||||
|
||||
def playsong(song): # this function plays your song
|
||||
a = 0 # this variable keeps track of the visualiser bars
|
||||
for i in range(len(song)):
|
||||
|
@ -127,7 +131,7 @@ def playsong(song): # this function plays your song
|
|||
else:
|
||||
playtone(tones[song[i]])
|
||||
explorer.set_pen(0, 255, 0) # switch to green pen
|
||||
explorer.rectangle(a, 240 - (int((tones[song[i]])/21)), 5, 240) # draw a green bar corresponding to the frequency of the note
|
||||
explorer.rectangle(a, 240 - (int((tones[song[i]]) / 21)), 5, 240) # draw a green bar corresponding to the frequency of the note
|
||||
a += 7
|
||||
if a >= 240: # clears the screen if the green bars reach the right hand edge
|
||||
clear()
|
||||
|
@ -136,6 +140,7 @@ def playsong(song): # this function plays your song
|
|||
utime.sleep(0.15) # change this number if you want to alter how long the notes play for
|
||||
bequiet()
|
||||
|
||||
|
||||
clear()
|
||||
playsong(song)
|
||||
clear()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
## This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Explorer's screen and RGB LED . If you're into rainbows, HSV (Hue, Saturation, Value) is very useful!
|
||||
# This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Explorer's screen and RGB LED . If you're into rainbows, HSV (Hue, Saturation, Value) is very useful!
|
||||
|
||||
import utime
|
||||
import picoexplorer as display
|
||||
|
@ -7,16 +7,17 @@ import picoexplorer as display
|
|||
buf = bytearray(display.get_width() * display.get_height() * 2)
|
||||
display.init(buf)
|
||||
|
||||
|
||||
# From CPython Lib/colorsys.py
|
||||
def hsv_to_rgb(h, s, v):
|
||||
if s == 0.0:
|
||||
return v, v, v
|
||||
i = int(h*6.0)
|
||||
f = (h*6.0) - i
|
||||
p = v*(1.0 - s)
|
||||
q = v*(1.0 - s*f)
|
||||
t = v*(1.0 - s*(1.0-f))
|
||||
i = i%6
|
||||
i = int(h * 6.0)
|
||||
f = (h * 6.0) - i
|
||||
p = v * (1.0 - s)
|
||||
q = v * (1.0 - s * f)
|
||||
t = v * (1.0 - s * (1.0 - f))
|
||||
i = i % 6
|
||||
if i == 0:
|
||||
return v, t, p
|
||||
if i == 1:
|
||||
|
@ -30,6 +31,7 @@ def hsv_to_rgb(h, s, v):
|
|||
if i == 5:
|
||||
return v, p, q
|
||||
|
||||
|
||||
h = 0
|
||||
|
||||
while True:
|
||||
|
@ -39,7 +41,7 @@ while True:
|
|||
display.clear() # Fill the screen with the colour
|
||||
display.set_pen(0, 0, 0) # Set pen to black
|
||||
display.text("pico disco!", 25, 20, 240, 6) # Add some text
|
||||
display.text("\o/ \o/ \o/ \o/ \o/ \o/ \o/ \o/ \o/", 25, 120, 240, 4) # and some more text
|
||||
display.text("\\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/", 25, 120, 240, 4) # and some more text
|
||||
display.text("oontz oontz oontz", 25, 220, 240, 2) # and a bit more tiny text
|
||||
display.update() # Update the display
|
||||
utime.sleep(1.0 / 60)
|
||||
utime.sleep(1.0 / 60)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# This example takes the temperature from the Pico's onboard temperature sensor, and displays it on Pico Explorer, along with a little pixelly graph.
|
||||
# It's based on the thermometer example in the "Getting Started with MicroPython on the Raspberry Pi Pico" book, which is a great read if you're a beginner!
|
||||
|
||||
import machine
|
||||
import utime
|
||||
import machine
|
||||
import utime
|
||||
|
||||
# Pico Explorer boilerplate
|
||||
import picoexplorer as display
|
||||
|
@ -12,16 +12,16 @@ display_buffer = bytearray(width * height * 2)
|
|||
display.init(display_buffer)
|
||||
|
||||
# reads from Pico's temp sensor and converts it into a more manageable number
|
||||
sensor_temp = machine.ADC(4)
|
||||
conversion_factor = 3.3 / (65535)
|
||||
sensor_temp = machine.ADC(4)
|
||||
conversion_factor = 3.3 / (65535)
|
||||
|
||||
i = 0
|
||||
|
||||
while True:
|
||||
# the following two lines do some maths to convert the number from the temp sensor into celsius
|
||||
reading = sensor_temp.read_u16() * conversion_factor
|
||||
temperature = round(27 - (reading - 0.706) / 0.001721)
|
||||
|
||||
temperature = round(27 - (reading - 0.706) / 0.001721)
|
||||
|
||||
# this if statement clears the display once the graph reaches the right hand side of the display
|
||||
if i >= (width + 1):
|
||||
i = 0
|
||||
|
@ -34,23 +34,23 @@ while True:
|
|||
display.set_pen(255, 0, 0)
|
||||
if temperature < 13:
|
||||
display.set_pen(0, 0, 255)
|
||||
|
||||
|
||||
# draws the reading as a tall, thin rectangle
|
||||
display.rectangle(i, height - (temperature * 6), 6, height)
|
||||
|
||||
|
||||
# draws a white background for the text
|
||||
display.set_pen(255, 255, 255)
|
||||
display.rectangle(1, 1, 65, 33)
|
||||
|
||||
|
||||
# writes the reading as text in the white rectangle
|
||||
display.set_pen(0, 0, 0)
|
||||
display.text("{:.0f}".format(temperature) + "c", 3, 3, 0, 4)
|
||||
|
||||
display.text("{:.0f}".format(temperature) + "c", 3, 3, 0, 4)
|
||||
|
||||
# time to update the display
|
||||
display.update()
|
||||
|
||||
|
||||
# waits for 5 seconds
|
||||
utime.sleep(5)
|
||||
|
||||
utime.sleep(5)
|
||||
|
||||
# the next tall thin rectangle needs to be drawn 6 pixels to the right of the last one
|
||||
i += 6
|
||||
i += 6
|
||||
|
|
|
@ -22,7 +22,7 @@ while True:
|
|||
colour_index = 0
|
||||
else:
|
||||
button = 0
|
||||
for find in range (0, NUM_PADS):
|
||||
for find in range(0, NUM_PADS):
|
||||
# check if this button is pressed and no other buttons are pressed
|
||||
if button_states & 0x01 > 0:
|
||||
if not (button_states & (~0x01)) > 0:
|
||||
|
@ -30,8 +30,8 @@ while True:
|
|||
break
|
||||
button_states >>= 1
|
||||
button += 1
|
||||
|
||||
for i in range (0, NUM_PADS):
|
||||
|
||||
for i in range(0, NUM_PADS):
|
||||
if (lit >> i) & 0x01:
|
||||
if colour_index == 0:
|
||||
keypad.illuminate(i, 0x00, 0x20, 0x00)
|
||||
|
@ -47,7 +47,7 @@ while True:
|
|||
keypad.illuminate(i, 0x00, 0x20, 0x20)
|
||||
else:
|
||||
keypad.illuminate(i, 0x05, 0x05, 0x05)
|
||||
|
||||
|
||||
keypad.update()
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
time.sleep(0.1)
|
||||
|
|
|
@ -10,8 +10,9 @@ tail = 12
|
|||
|
||||
width = scroll.get_width()
|
||||
height = scroll.get_height()
|
||||
|
||||
while True:
|
||||
scroll.clear();
|
||||
scroll.clear()
|
||||
for y in range(0, height):
|
||||
for x in range(0, width):
|
||||
if x < 3 and y < 3 and scroll.is_pressed(scroll.BUTTON_A):
|
||||
|
@ -27,7 +28,6 @@ while True:
|
|||
for b in range(0, loop):
|
||||
if m == (i + (loop - b)) % loop and b < tail:
|
||||
scroll.set_pixel(x, y, br_mult * (tail - b))
|
||||
|
||||
|
||||
scroll.update()
|
||||
i += 1
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
import math
|
||||
import time
|
||||
import picounicorn
|
||||
|
||||
picounicorn.init()
|
||||
|
||||
|
||||
# From CPython Lib/colorsys.py
|
||||
def hsv_to_rgb(h, s, v):
|
||||
if s == 0.0:
|
||||
return v, v, v
|
||||
i = int(h*6.0)
|
||||
f = (h*6.0) - i
|
||||
p = v*(1.0 - s)
|
||||
q = v*(1.0 - s*f)
|
||||
t = v*(1.0 - s*(1.0-f))
|
||||
i = i%6
|
||||
i = int(h * 6.0)
|
||||
f = (h * 6.0) - i
|
||||
p = v * (1.0 - s)
|
||||
q = v * (1.0 - s * f)
|
||||
t = v * (1.0 - s * (1.0 - f))
|
||||
i = i % 6
|
||||
if i == 0:
|
||||
return v, t, p
|
||||
if i == 1:
|
||||
|
@ -27,6 +26,7 @@ def hsv_to_rgb(h, s, v):
|
|||
if i == 5:
|
||||
return v, p, q
|
||||
|
||||
|
||||
w = picounicorn.get_width()
|
||||
h = picounicorn.get_height()
|
||||
|
||||
|
@ -46,4 +46,4 @@ for x in range(w):
|
|||
for y in range(h):
|
||||
picounicorn.set_pixel(x, y, 0, 0, 0)
|
||||
|
||||
print("Button A pressed!")
|
||||
print("Button A pressed!")
|
||||
|
|
Ładowanie…
Reference in New Issue