Skip to content

Commit

Permalink
Added another colour effect, and doc stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ZodiusInfuser committed Jul 30, 2024
1 parent 706a601 commit 8efcf55
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 25 deletions.
2 changes: 2 additions & 0 deletions boards/PIMORONI_TINYFX/uf2-manifest.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
main.py
examples/*.py
examples/effects/*.py
examples/effects/mono/*.py
examples/effects/colour/*.py
examples/showcase/*.py
lib/*.py
lib/picofx/*.py
Expand Down
91 changes: 71 additions & 20 deletions examples/tiny_fx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
These are micropython examples for the Pimoroni [TinyFX](https://shop.pimoroni.com/products/tiny_fx), a stamp-sized light and sound effects controller board for model making, construction kits, and dioramas.

- [Function Examples](#function-examples)
- [Effect Examples](#effect-examples)
- [Mono Effect Examples](#mono-effect-examples)
- [Single Blink](#single-blink)
- [Blink Wave](#blink-wave)
- [Binary Counter](#binary-counter)
- [Single Flashing](#single-flashing)
- [Single Flicker](#single-flicker)
- [Single Pulse](#single-pulse)
- [Single Random](#single-random)
- [Blink Wave](#blink-wave)
- [Flashing Sequence](#flashing-sequence)
- [Pulse Wave](#pulse-wave)
- [Binary Counter](#binary-counter)
- [Traffic Light](#traffic-light)
- [Wave Sequence](#wave-sequence)
- [Colour Effect Examples](#colour-effect-examples)
- [Rainbow](#rainbow)
- [Random](#random)
- [Hue Step](#hue-step)
- [Audio Examples](#audio-examples)
- [Showcase Examples](#showcase-examples)
- [Rescue Vehicle](#rescue-vehicle)
- [Ship Thrusters](#ship-thrusters)
- [Space Tales](#space-tales)
- [Space Tales with PIR Sensor](#space-tales-with-pir-sensor)
Expand All @@ -22,48 +30,86 @@ These are micropython examples for the Pimoroni [TinyFX](https://shop.pimoroni.c



## Effect Examples
## Mono Effect Examples

### Single Blink
[effects/single_blink.py](effects/single_blink.py)
[effects/mono/single_blink.py](effects/mono/single_blink.py)

Play a blinking effect on one of TinyFX's outputs.


### Blink Wave
[effects/blink_wave.py](effects/blink_wave.py)
### Single Flashing
[effects/mono/single_flashing.py](effects/mono/single_flashing.py)

Play a wave of blinks on TinyFX's outputs.
Play a flashing effect on one of TinyFX's outputs.


### Binary Counter
[effects/binary_counter.py](effects/binary_counter.py)
### Single Flicker
[effects/mono/single_flicker.py](effects/mono/single_flicker.py)

Play an incrementing binary counter on TinyFX's outputs.
Play a flickering effect on one of TinyFX's outputs.


### Single Pulse
[effects/single_pulse.py](effects/single_pulse.py)
[effects/mono/single_pulse.py](effects/mono/single_pulse.py)

Play a pulsing effect on one of TinyFX's outputs.


### Single Random
[effects/mono/single_random.py](effects/mono/single_random.py)

Play a randomly changing brightness effect on one of TinyFX's outputs.


### Blink Wave
[effects/mono/blink_wave.py](effects/mono/blink_wave.py)

Play a wave of blinks on TinyFX's outputs.


### Flashing Sequence
[effects/mono/flashing_sequence.py](effects/mono/flashing_sequence.py)

Play a flashing sequence across TinyFX's outputs.


### Pulse Wave
[effects/pulse_wave.py](effects/pulse_wave.py)
[effects/mono/pulse_wave.py](effects/mono/pulse_wave.py)

Play a wave of pulses on TinyFX's outputs.


### Binary Counter
[effects/binary_counter.py](effects/binary_counter.py)

Play an incrementing binary counter on TinyFX's outputs.


### Traffic Light
[effects/traffic_light.py](effects/traffic_light.py)
[effects/mono/traffic_light.py](effects/mono/traffic_light.py)

Play a traffic light sequence on TinyFX's outputs.


### Wave Sequence
[effects/wave.py](effects/wave.py)
## Colour Effect Examples

### Rainbow
[effects/colour/rainbow.py](effects/colour/rainbow.py)

Read Yukon's onboard Buttons.
Play a rainbow effect on TinyFX's RGB output.


### Random
[effects/colour/random.py](effects/colour/random.py)

Play a randomly changing brightness and colour effect on TinyFX's RGB output.


### Hue Step
[effects/colour/hue_step.py](effects/colour/hue_step.py)

Play a stepped hue effect on TinyFX's RGB output.


## Audio Examples
Expand All @@ -72,6 +118,12 @@ Read Yukon's onboard Buttons.

## Showcase Examples

### Rescue Vehicle
[showcase/rescue_vehicle.py](showcase/rescue_vehicle.py)

Play an alternating flashing sequence on two of TinyFX's outputs, recreating the effect of rescue vehicle beacons. The other outputs are static for illuminated head and tail lights.


### Ship Thrusters
[showcase/ship_thrusters.py](showcase/ship_thrusters.py)

Expand All @@ -87,5 +139,4 @@ Play effects for each space themed "postcard".
### Space Tales with PIR Sensor
[showcase/space_tales_pir.py](showcase/space_tales_with_pir.py)

Play effects for each space themed "postcard" when someone walks past.
A PIR sensor is used to activate the effect, which will turn off after a certain time.
Play effects for each space themed "postcard" when someone walks past. A PIR sensor is used to activate the effect, which will turn off after a certain time.
35 changes: 35 additions & 0 deletions examples/tiny_fx/examples/effects/colour/hue_step.py
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()
6 changes: 3 additions & 3 deletions picofx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def set_hsv(self, h, s, v):


class Updateable:
def __init__(self, speed):
self.speed = speed
def __init__(self):
pass

def tick(self, delta_ms):
pass
Expand All @@ -80,7 +80,7 @@ def reset(self):

class Cycling(Updateable):
def __init__(self, speed):
super().__init__(speed)
self.speed = speed
self.__offset_ms = 0
self.__offset = 0

Expand Down
4 changes: 3 additions & 1 deletion picofx/colour/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

from .colour import RGBFX, HSVFX
from .rainbow import RainbowFX, RainbowWaveFX
from .step import HueStepFX

COLOUR_EFFECTS = [
RGBFX,
HSVFX,
RainbowFX,
RainbowWaveFX
RainbowWaveFX,
HueStepFX
]
30 changes: 30 additions & 0 deletions picofx/colour/step.py
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
1 change: 0 additions & 1 deletion picofx/mono/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class BinaryCounterFX(Updateable):

def __init__(self, interval=0.1, count=0, step=1):
self.interval = interval
self.counter = count
Expand Down

0 comments on commit 8efcf55

Please sign in to comment.