-
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.
Added another colour effect, and doc stuff
- Loading branch information
1 parent
706a601
commit 8efcf55
Showing
8 changed files
with
144 additions
and
25 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
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() |
File renamed without changes.
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,30 @@ | ||
# SPDX-FileCopyrightText: 2024 Christopher Parrott for Pimoroni Ltd | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from picofx import Updateable, rgb_from_hsv | ||
|
||
|
||
class HueStepFX(Updateable): | ||
def __init__(self, interval=1.0, hue=0.0, sat=1.0, val=1.0, steps=6): | ||
self.interval = interval | ||
self.start_hue = hue | ||
self.sat = sat | ||
self.val = val | ||
self.__steps = steps | ||
self.__current_step = 0 | ||
self.__time = 0 | ||
|
||
def __call__(self): | ||
hue = (self.start_hue + (self.__current_step / self.__steps)) % 1.0 | ||
r, g, b = rgb_from_hsv(hue, self.sat, self.val) | ||
return int(r * 255), int(g * 255), int(b * 255) | ||
|
||
def tick(self, delta_ms): | ||
self.__time += delta_ms | ||
|
||
# Check if the dim duration has elapsed | ||
if self.__time >= (self.interval * 1000): | ||
self.__time -= (self.interval * 1000) | ||
|
||
self.__current_step = (self.__current_step + 1) % self.__steps |
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