-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional colour and static examples
- Loading branch information
1 parent
4ba901f
commit 1407620
Showing
8 changed files
with
253 additions
and
2 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
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 RGBBlinkFX, RED, YELLOW, GREEN, CYAN, BLUE, MAGENTA | ||
|
||
""" | ||
Play a blinking sequence effect on TinyFX's RGB output. Each blink in the sequence can be a different colour. | ||
Press "Boot" to exit the program. | ||
""" | ||
|
||
# Constants | ||
COLOURS = [RED, YELLOW, GREEN, CYAN, BLUE, MAGENTA] | ||
|
||
# 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 = RGBBlinkFX(colour=COLOURS, # The colour (or colours to blink in sequence) | ||
speed=0.5) # The speed to cycle through colours at, with 1.0 being 1 second | ||
|
||
|
||
# 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.shutdown() |
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,34 @@ | ||
from tiny_fx import TinyFX | ||
from picofx import ColourPlayer | ||
from picofx.colour import HSVFX | ||
|
||
""" | ||
Show a static colour on TinyFX's RGB output, using HSV. | ||
Press "Boot" to exit the program. | ||
""" | ||
|
||
# Constants | ||
HUE = 0.0 # The colour's hue (from 0.0 to 1.0) | ||
SAT = 1.0 # The colour's saturation (from 0.0 to 1.0) | ||
VAL = 1.0 # The colour's value/brightness (from 0.0 to 1.0) | ||
|
||
# Variables | ||
tiny = TinyFX() # Create a new TinyFX object | ||
player = ColourPlayer(tiny.rgb) # Create a new effect player to control TinyFX's RGB output | ||
|
||
# Set up the colour effect to play | ||
player.effects = HSVFX(HUE, SAT, VAL) | ||
|
||
# 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.shutdown() |
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,34 @@ | ||
from tiny_fx import TinyFX | ||
from picofx import ColourPlayer | ||
from picofx.colour import RGBFX | ||
|
||
""" | ||
Show a static colour on TinyFX's RGB output. | ||
Press "Boot" to exit the program. | ||
""" | ||
|
||
# Constants | ||
R = 255 # The amount of red (from 0 to 255) | ||
G = 0 # The amount of green (from 0 to 255) | ||
B = 0 # The amount of blue (from 0 to 255) | ||
|
||
# Variables | ||
tiny = TinyFX() # Create a new TinyFX object | ||
player = ColourPlayer(tiny.rgb) # Create a new effect player to control TinyFX's RGB output | ||
|
||
# Set up the colour effect to play | ||
player.effects = RGBFX(R, G, B) | ||
|
||
# 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.shutdown() |
43 changes: 43 additions & 0 deletions
43
examples/tiny_fx/examples/effects/mono/static_brightness.py
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,43 @@ | ||
from tiny_fx import TinyFX | ||
from picofx import MonoPlayer | ||
from picofx.mono import StaticFX | ||
|
||
""" | ||
Show a static brightness on one of TinyFX's outputs. | ||
Press "Boot" to exit the program. | ||
""" | ||
|
||
# Constants | ||
BRIGHTNESS = 1.0 # The brightness (from 0.0 to 1.0) | ||
|
||
# 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 and set up a blink effect to play | ||
player.effects = [ | ||
StaticFX(BRIGHTNESS), | ||
|
||
# No effects played on the rest of the outputs (unnecessary to list, but show for clarity) | ||
None, | ||
None, | ||
None, | ||
None, | ||
None, | ||
] | ||
|
||
|
||
# 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.shutdown() |
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,48 @@ | ||
# SPDX-FileCopyrightText: 2024 Christopher Parrott for Pimoroni Ltd | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from picofx import CyclingAction | ||
|
||
|
||
# Derived from maltheim's example: https://forums.pimoroni.com/t/rgb-led-kit-for-tiny-fx-tutorial/25293/15 | ||
class RGBBlinkFX(CyclingAction): | ||
""" | ||
Blinks the RGB LED according to the speed, phase and duty cycle. | ||
The colour argument is a single tuple of the form (R,G,B), or a | ||
list of such tuples. A None colour argument defaults to red. | ||
:param: colour an RGB tuple as the colour or colours of the blink | ||
:param: speed the speed of the blink, where 1.0 is 1 second, 0.5 is 2 seconds, etc. | ||
:param: phase the phase of the blink | ||
:param: duty the duty cycle of the blink | ||
""" | ||
def __init__(self, colour=None, speed=1, phase=0.0, duty=0.5): | ||
super().__init__(speed) | ||
self.phase = phase | ||
self.duty = duty | ||
self.__colours = [] | ||
self.__index = 0 | ||
if colour is None: | ||
self.__colours.append((255, 0, 0)) | ||
elif isinstance(colour, tuple) and len(colour) == 3: | ||
self.__colours.append(colour) | ||
elif isinstance(colour, list): | ||
self.__colours.extend(colour) | ||
else: | ||
raise TypeError("colour is not a supported type. Expected a tuple of 3 numbers, a list of tuples, or None.") | ||
|
||
def __call__(self): | ||
percent = (self.__offset + self.phase) % 1.0 | ||
if percent < self.duty: | ||
colour = self.__colours[self.__index] | ||
return int(colour[0]), int(colour[1]), int(colour[2]) | ||
else: | ||
return 0, 0, 0 | ||
|
||
def next(self): | ||
self.__index = (self.__index + 1) % len(self.__colours) | ||
|
||
def prev(self): | ||
self.__index = (self.__index - 1) % len(self.__colours) |