-
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.
Merge pull request #4 from pimoroni/patch-examples
Examples for TinyFX, with related effects and functional tweaks
- Loading branch information
Showing
46 changed files
with
1,290 additions
and
483 deletions.
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
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
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,35 @@ | ||
from tiny_fx import TinyFX | ||
from picofx import ColourPlayer | ||
from picofx.colour import HueStepFX | ||
|
||
""" | ||
Play a stepped hue effect on TinyFX's RGB output. | ||
Press "Boot" to exit the program. | ||
""" | ||
|
||
# Variables | ||
tiny = TinyFX() # Create a new TinyFX object to interact with the board | ||
player = ColourPlayer(tiny.rgb) # Create a new effect player to control TinyFX's RGB output | ||
|
||
|
||
# Create and set up a rainbow effect to play | ||
player.effects = HueStepFX(interval=1.0, # The time (in seconds) between each hue step | ||
hue=0.0, # The hue of the colour to start at (from 0.0 to 1.0) | ||
sat=1.0, # The saturation/intensity of the colour (from 0.0 to 1.0) | ||
val=1.0, # The value/brightness of the colour (from 0.0 to 1.0) | ||
steps=6) # The number of steps to take around the colour wheel | ||
|
||
|
||
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt) | ||
try: | ||
player.start() # Start the effects running | ||
|
||
# Loop until the effect stops or the "Boot" button is pressed | ||
while player.is_running() and not tiny.boot_pressed(): | ||
pass | ||
|
||
# Stop any running effects and turn off all the outputs | ||
finally: | ||
player.stop() | ||
tiny.clear() |
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,33 @@ | ||
from tiny_fx import TinyFX | ||
from picofx import ColourPlayer | ||
from picofx.colour import RainbowFX | ||
|
||
""" | ||
Play a rainbow effect on TinyFX's RGB output. | ||
Press "Boot" to exit the program. | ||
""" | ||
|
||
# Variables | ||
tiny = TinyFX() # Create a new TinyFX object to interact with the board | ||
player = ColourPlayer(tiny.rgb) # Create a new effect player to control TinyFX's RGB output | ||
|
||
|
||
# Create and set up a rainbow effect to play | ||
player.effects = RainbowFX(speed=0.2, # The speed to cycle through colours at, with 1.0 being 1 second | ||
sat=1.0, # The saturation/intensity of the colour (from 0.0 to 1.0) | ||
val=1.0) # The value/brightness of the colour (from 0.0 to 1.0) | ||
|
||
|
||
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt) | ||
try: | ||
player.start() # Start the effects running | ||
|
||
# Loop until the effect stops or the "Boot" button is pressed | ||
while player.is_running() and not tiny.boot_pressed(): | ||
pass | ||
|
||
# Stop any running effects and turn off all the outputs | ||
finally: | ||
player.stop() | ||
tiny.clear() |
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,48 @@ | ||
from tiny_fx import TinyFX | ||
from picofx import MonoPlayer | ||
from picofx.mono import RandomFX | ||
|
||
""" | ||
Play a randomly changing brightness and colour effect on TinyFX's RGB output. | ||
Press "Boot" to exit the program. | ||
""" | ||
|
||
# Constants | ||
INTERVAL = 0.2 # The time (in seconds) between each random brightness | ||
BRIGHTNESS_MIN = 0.0 # The min brightness to randomly go down to | ||
BRIGHTNESS_MAX = 1.0 # The max brightness to randomly go up to | ||
|
||
# Variables | ||
tiny = TinyFX() # Create a new TinyFX object to interact with the board | ||
player = MonoPlayer([tiny.rgb.led_r, # Create a new effect player to control TinyFX's RGB output as mono outputs | ||
tiny.rgb.led_g, | ||
tiny.rgb.led_b]) | ||
|
||
|
||
# Create and set up a blink effect to play | ||
player.effects = [ | ||
RandomFX(interval=INTERVAL, | ||
brightness_min=BRIGHTNESS_MIN, | ||
brightness_max=BRIGHTNESS_MAX), | ||
RandomFX(interval=INTERVAL, | ||
brightness_min=BRIGHTNESS_MIN, | ||
brightness_max=BRIGHTNESS_MAX), | ||
RandomFX(interval=INTERVAL, | ||
brightness_min=BRIGHTNESS_MIN, | ||
brightness_max=BRIGHTNESS_MAX) | ||
] | ||
|
||
|
||
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt) | ||
try: | ||
player.start() # Start the effects running | ||
|
||
# Loop until the effect stops or the "Boot" button is pressed | ||
while player.is_running() and not tiny.boot_pressed(): | ||
pass | ||
|
||
# Stop any running effects and turn off all the outputs | ||
finally: | ||
player.stop() | ||
tiny.clear() |
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,42 @@ | ||
from tiny_fx import TinyFX | ||
from picofx import MonoPlayer | ||
from picofx.mono import BinaryCounterFX | ||
|
||
""" | ||
Play an incrementing binary counter on TinyFX's outputs. | ||
Press "Boot" to exit the program. | ||
""" | ||
|
||
# Variables | ||
tiny = TinyFX() # Create a new TinyFX object to interact with the board | ||
player = MonoPlayer(tiny.outputs) # Create a new effect player to control TinyFX's mono outputs | ||
|
||
|
||
# Create a BinaryCounterFX effect | ||
binary = BinaryCounterFX(interval=0.1) # The time (in seconds) between each increment of the binary counter | ||
|
||
|
||
# Set up the binary effect to play. Each output shows a different bit of the counter | ||
player.effects = [ | ||
binary(0), | ||
binary(1), | ||
binary(2), | ||
binary(3), | ||
binary(4), | ||
binary(5) | ||
] | ||
|
||
|
||
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt) | ||
try: | ||
player.start() # Start the effects running | ||
|
||
# Loop until the effect stops or the "Boot" button is pressed | ||
while player.is_running() and not tiny.boot_pressed(): | ||
pass | ||
|
||
# Stop any running effects and turn off all the outputs | ||
finally: | ||
player.stop() | ||
tiny.clear() |
Oops, something went wrong.