linting cheerlights example and examples readme

pull/442/head
helgibbons 2022-07-12 19:43:51 +01:00
rodzic 07ef40bc2b
commit 32455e6092
2 zmienionych plików z 33 dodań i 12 usunięć

Wyświetl plik

@ -1,44 +1,64 @@
# Pico Explorer MicroPython Examples <!-- omit in toc --> # Pico Explorer MicroPython Examples <!-- omit in toc -->
- - [PicoGraphics](#picographics)
- [Non-Wireless Examples](#non-wireless-examples)
- [Balls Demo](#balls-demo)
- [Button Test](#button-test)
- [Demo](#demo)
- [Noise](#noise)
- [Rainbow](#rainbow)
- [Thermometer](#thermometer)
- [Weather Station (BME280)](#weather-station-bme280)
- [Weather Station (BME68X)](#weather-station-bme68x)
- [Wireless Examples](#wireless-examples)
- [Cheerlights](#cheerlights)
## PicoGraphics ## PicoGraphics
You can draw on Pico Explorer's display using our tiny PicoGraphics display library. You can draw on Pico Explorer's display using our tiny PicoGraphics display library.
- [PicoGraphics MicroPython function reference](../../modules/picographics) - [PicoGraphics MicroPython function reference](../../modules/picographics)
## Non-Wireless Examples ## Non-Wireless Examples
### Balls Demo ### Balls Demo
[balls_demo.py](balls_demo.py)
Simple LCD demo showing 100 bouncy balls! LCD demo showing 100 bouncy balls!
### Button Test ### Button Test
[button_test.py](button_test.py)
This example shows you a simple, non-interrupt way of reading Pico Explorer's buttons with a loop that checks to see if buttons are pressed. This example shows you a simple, non-interrupt way of reading Pico Explorer's buttons with a loop that checks to see if buttons are pressed.
### Demo ### Demo
[demo.py](demo.py)
A demo of all Pico Explorer's functions. Connect analog inputs like potentiometers up to ADC0-ADC3 and motors to the motor channels for best results. Connect AUDIO to GP0 with a jumper wire to hear noise. A demo of all Pico Explorer's functions. Connect analog inputs like potentiometers up to ADC0-ADC3 and motors to the motor channels for best results. Connect AUDIO to GP0 with a jumper wire to hear noise.
### Noise ### Noise
[noise.py](noise.py)
This example shows you how you can use Pico Explorer's onboard buzzer as a speaker to play different notes and string them together into a bleepy tune (you'll need to connect AUDIO to GP0 with a jumper wire to hear noise). This example shows you how you can use Pico Explorer's onboard buzzer as a speaker to play different notes and string them together into a bleepy tune (you'll need to connect AUDIO to GP0 with a jumper wire to hear noise).
### Rainbow ### Rainbow
[rainbow.py](rainbow.py)
This example borrows a CircuitPython hsv to rgb function to cycle through some rainbows on Pico Explorer's screen. This example borrows a CircuitPython hsv to rgb function to cycle through some rainbows on Pico Explorer's screen.
### Thermometer ### Thermometer
[thermometer.py](thermometer.py)
This example takes the temperature from the Pico's onboard temperature sensor, and displays it on Pico Explorer, along with a little pixelly graph. This example takes the temperature from the Pico's onboard temperature sensor, and displays it on Pico Explorer, along with a little pixelly graph.
### Weather Station (BME280) ### Weather Station (BME280)
[weatherstation_BME280.py](weatherstation_BME280.py)
Plug a BME280 breakout into your Pico Explorer and make a little indoor weather station, with barometer style descriptions. Plug a [BME280 breakout](https://shop.pimoroni.com/products/bme280-breakout) into your Pico Explorer and make a little indoor weather station, with barometer style descriptions.
### Weather Station (BME68x) ### Weather Station (BME68X)
[weatherstation_BME68X.py](weatherstation_BME68X.py)
Plug a BME680 or BME688 breakout into your Pico Explorer to make a little indoor weather station, with barometer style descriptions. Plug a [BME680](https://shop.pimoroni.com/products/bme680-breakout) or [BME688](https://shop.pimoroni.com/products/bme688-breakout) breakout into your Pico Explorer to make a little indoor weather station, with barometer style descriptions.
## Wireless Examples ## Wireless Examples
@ -47,5 +67,7 @@ The wireless examples need `network_manager.py` and `WIFI_CONFIG.py` to be saved
You'll also need to install the `micropython-urllib.urequest` library using Thonny's 'Tools' > 'Manage Packages'. You'll also need to install the `micropython-urllib.urequest` library using Thonny's 'Tools' > 'Manage Packages'.
### Cheerlights ### Cheerlights
[cheerlights.py](cheerlights.py)
This Pico W example sets your Pico Explorer's screen (and optionally, a [RGB LED](https://shop.pimoroni.com/products/led-rgb-clear-common-cathode)) to the current #cheerlights colour.
This Pico W example sets your Pico Explorer's screen to the current #cheerlights colour.

Wyświetl plik

@ -42,7 +42,7 @@ def status_handler(mode, status, ip):
def hex_to_rgb(hex): def hex_to_rgb(hex):
# converts a hex colour code into RGB # converts a hex colour code into RGB
h = hex.lstrip('#') h = hex.lstrip('#')
r, g, b = (int(h[i:i+2], 16) for i in (0, 2, 4)) r, g, b = (int(h[i:i + 2], 16) for i in (0, 2, 4))
return r, g, b return r, g, b
@ -66,17 +66,17 @@ led = RGBLED(0, 1, 2, invert=False)
while True: while True:
# connect to wifi # connect to wifi
uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)) uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK))
# open the json file # open the json file
print(f"Requesting URL: {URL}") print(f"Requesting URL: {URL}")
socket = urequest.urlopen(URL) socket = urequest.urlopen(URL)
data = ujson.load(socket) data = ujson.load(socket)
socket.close() socket.close()
print(f"Data obtained!") print("Data obtained!")
# extract hex colour from the data # extract hex colour from the data
hex = data['field2'] hex = data['field2']
# and convert it to RGB # and convert it to RGB
r, g, b = hex_to_rgb(hex) r, g, b = hex_to_rgb(hex)
@ -93,9 +93,8 @@ while True:
# light up RGB LED # light up RGB LED
led.set_rgb(r, g, b) led.set_rgb(r, g, b)
print(f"RGB LED set to {hex}") print(f"RGB LED set to {hex}")
# sleep # sleep
print(f"""Sleeping for {UPDATE_INTERVAL} seconds. print(f"""Sleeping for {UPDATE_INTERVAL} seconds.
""") """)
time.sleep(UPDATE_INTERVAL) time.sleep(UPDATE_INTERVAL)