-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial setup of build with added W example
- Loading branch information
1 parent
2a868d5
commit d8927c9
Showing
4 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# TinyFX W Micropython Examples <!-- omit in toc --> | ||
|
||
These are micropython examples for the wireless functionality of the Pimoroni [TinyFX W](https://shop.pimoroni.com/products/tiny_fx_w), a stamp-sized light and sound effects controller board for model making, construction kits, and dioramas. | ||
|
||
For examples that show off the rest of the board's functions, refer to the regular [TinyFX Micropython Examples](../tiny_fx/README.md) | ||
|
||
- [WiFi Examples](#wifi-examples) | ||
- [Random Colour](#random-colour) | ||
|
||
|
||
## WiFi Examples | ||
|
||
### Random Colour | ||
[wifi/random_colour.py](examples/wifi/random_colour.py) | ||
|
||
Show the state of TinyFX's Boot button on its RGB output. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import time | ||
import network | ||
import requests | ||
from tiny_fx import TinyFX | ||
|
||
""" | ||
Press "Boot" to exit the program. | ||
""" | ||
# secrets.py should contain: | ||
# WIFI_SSID = "" | ||
# WIFI_PASSWORD = "" | ||
|
||
try: | ||
from secrets import WIFI_SSID, WIFI_PASSWORD | ||
except ImportError: | ||
print("Create secrets.py with your WiFi credentials") | ||
|
||
|
||
# Constants | ||
MONO_NAMES = ("One", "Two", "Three", "Four", "Five", "Six") | ||
COLOUR_NAMES = ("R", "G", "B") | ||
|
||
# Variables | ||
tiny = TinyFX() # Create a new TinyFX object to interact with the board | ||
|
||
|
||
# Connect to WLAN | ||
wlan = network.WLAN(network.STA_IF) | ||
wlan.active(True) | ||
wlan.connect(WIFI_SSID, WIFI_PASSWORD) | ||
|
||
while wlan.isconnected() == False: | ||
print('Waiting for connection...') | ||
time.sleep(1) | ||
|
||
ip = wlan.ifconfig()[0] | ||
print(f'Connected on {ip}') | ||
|
||
|
||
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt) | ||
try: | ||
while True: | ||
req = requests.get("https://random-flat-colors.vercel.app/api/random?count=2").json() | ||
|
||
mono = tuple(int(req['colors'][0][i:i+1], 16) / 15 for i in range(1, 7)) | ||
colour = tuple(int(req['colors'][1][i:i+2], 16) for i in (1, 3, 5)) | ||
|
||
for i in range(len(tiny.outputs)): | ||
tiny.outputs[i].brightness(mono[i]) | ||
print(f"{MONO_NAMES[i]} = {round(mono[i], 2)}", end=", ") | ||
|
||
tiny.rgb.set_rgb(*colour) | ||
for i in range(len(colour)): | ||
print(f"{COLOUR_NAMES[i]} = {colour[i]}", end=", ") | ||
|
||
print() | ||
|
||
time.sleep(5) | ||
|
||
# Turn off all the outputs | ||
finally: | ||
tiny.shutdown() | ||
wlan.disconnect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# secrets.py should contain: | ||
WIFI_SSID = "" | ||
WIFI_PASSWORD = "" |