Is there a tutorial for using the RGB LED Kit for Tiny FX?
Have you seen this?
picofx/examples/tiny_fx at main · pimoroni/picofx (github.com)
There are RGB examples here that may be worth a look see.
picofx/examples/tiny_fx/examples/effects/colour at main · pimoroni/picofx (github.com)
I guess I should have been more specific. I meant how to connect the RGB LED Kit to the Tiny FX. But now that I’ve blundered my way through that, I’d like to start with something even more basic than the examples. Is there an example of how to get it to display a specific color?
This is one of my pet peeves, with the software side of things here. The examples are cool and do fancy things, but don’t help first timers with the basic getting started side of it.
Usually there is a function reference, but I don’t even see that?
I had a quick look but struck out trying to figure it code wise with what is provided. everything is import color this or that?
Looking at the Pinout Diagram.
GP 13 is Red In
GP 14 is Green In
GP 15 is Blue In
and
The RGB LED uses a common 5V out.
I would think setting GP 13 low would get you Red.
and setting GP 14 Low would get you Green, etc.
I have to agree that “hunt the examples” on Github is not the best way of getting started, even for someone with a bit of experience of working with Micropython.
This might work? JFYI, I don’t own a TinyFX.
from pimoroni import RGBLED
led = RGBLED(14, 15, 16)
led.set_rgb(0, 0, 0) # off
led.set_rgb(255, 0, 0) # Red ?
Is there a tutorial for using the RGB LED Kit for Tiny FX?
We do not currently have a learn guide for how to use the RGB LED Kit for Tiny FX.
Is there an example of how to get it to display a specific color?
I admit it’s not obviously named, but this example sets a specific colour: picofx/examples/tiny_fx/examples/function/read_button.py at main · pimoroni/picofx · GitHub
One of the showcase examples sets the RGB LED to a specific colour (ship_thrusters.py
) but this is even less obvious. Here is an absolute minimal example I’ve just whipped up:
from tiny_fx import TinyFX
from picofx import ColourPlayer
from picofx.colour import RGBFX
# 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(255, 0, 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.shutdown()
It’s untested but if it works I will add it to the picofx github.
This is one of my pet peeves, with the software side of things here. The examples are cool and do fancy things, but don’t help first timers with the basic getting started side of it.
A valid criticism for sure. I personally find it hard to get that first timer perspective when writing our examples. How minimal do we go? Most of our products have a required setup and loop structure, so at some point examples become the same with just one or two lines different. Is that good for learning? That’s a discussion for another time.
In this particular case, since the product’s more about dynamic effects, the lack of examples to set static colours is an oversight on my part.
Usually there is a function reference, but I don’t even see that?
The function references for the Pico FX library are here: picofx/picofx at main · pimoroni/picofx · GitHub
@ZodiusInfuser Thank you for the above info. I see that the function reference was there, just a bit hard to find IMHO. Just a matter of knowing what you looking for. ;)
It is a bit work in progress, but I’ve added a specific Tiny FX library reference, with getting started, to the PicoFX repo. picofx/docs/reference.md at main · pimoroni/picofx · GitHub
I would welcome it if people could give it a look. Also, please don’t hesitate to raise github issues for documentation and example improvements. For my products at least, I am more likely to get notifications for those, whereas anything on here is what Hel manages to spot and point me to ;)
That looks really helpful - thank you. All I feel we need are examples like the ones you have referenced and a link to find our way to the right place on Github.
I have my Tiny FX but unfortunately I have a lot to do with another project before I hook it all up. Those plugs are tiny! I will get around to it soon.
I’ve added a link to the library reference from the shop page which should hopefully make it a bit easier to find :)
For any other Tiny FX beginners like me, you’ll have more luck if you fix the typos in the example code. In the Getting Started section it says to create a “TinyFX” class called “tiny”. Then “tinyfx” is used instead in a few places. So under “Setting the Mono LED Outputs” where it says:
one = tinyfx.outputs[0]
also_one = tinyfx.one
Change it to say:
one = tiny.outputs[0]
also_one = tiny.one
Then under " Setting the RGB LED Output" where it says:
rgb = tinyfx.rgb
Change it to say:
rgb = tiny.rgb
I’ve now fixed those in the documentation.
If you look at the existing examples you can generally find the base class that is being extended, such as Updateable
or Cycling
(which extends Updateable
). These are all defined in tinyfx/lib/picofx/__init__.py
.
I wanted to blink the RGB LED so I looked at the existing mono BlinkFX class, then extended Cycling to make my own version for the RGB LED:
from picofx import Cycling
import itertools
from color import Color
class RgbBlinkFX(Cycling):
'''
Blinks the RGB LED according to the speed, phase and duty cycle.
The color argument is a single tuple of the form (i,R,G,B), or a
list of such tuples. A None color argument defaults to red.
: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
:param: color an RGB tuple as the color or colors of the blink
'''
def __init__(self, speed=1, phase=0.0, duty=0.5, color=None):
super().__init__(speed)
self.phase = phase
self.duty = duty
self._colors = []
self._counter = itertools.count()
if color is None:
# self._colors.append(Color.RED)
self._colors.append((0, 255, 0, 0))
elif isinstance(color, tuple):
self._colors.append(color)
elif type(color) is list:
self._colors.extend(color)
else:
raise Exception('unrecognised argument type.')
self._cycle = itertools.cycle(self._colors)
self._color = self._colors[0]
def __call__(self):
percent = (self.__offset + self.phase) % 1.0
if percent < self.duty:
if len(self._colors) == 1:
self._color = self._colors[0]
elif next(self._counter) % 5 == 0:
self._color = next(self._cycle)
_red = self._color[1]
_green = self._color[2]
_blue = self._color[3]
return _red, _green, _blue
else:
return 0, 0, 0
This uses a MicroPython version of itertools, which you can download from micropython-itertools.
I wrote a simple Color class, noting that the first value in the tuple is an index:
class Color(object):
# i R G B
WHITE = ( 1, 255.0, 255.0, 255.0)
BLACK = ( 2, 0.0, 0.0, 0.0)
RED = ( 3, 255.0, 0.0, 0.0)
YELLOW = ( 4, 255.0, 160.0, 0.0)
GREEN = ( 5, 0.0, 255.0, 0.0)
BLUE = ( 6, 0.0, 40.0, 255.0)
CYAN = ( 7, 0.0, 255.0, 255.0)
MAGENTA = ( 8, 255.0, 0.0, 255.0)
and of course you could add your own colors to that list.
I have a Starter Kit on the way. Looks like I’m going to be having some fun when it arrives. Lots of good info being posted in this thread. =)
Just put out a new release for Pico FX. Release Version v1.0.1 - Blinking RGB and Ws · pimoroni/picofx · GitHub
It includes examples for setting the RGB and mono LEDs to static colours, following my response to @Medwards (RGB LED Kit for Tiny FX Tutorial? - #7 by ZodiusInfuser), and adds a RGBBlinkFX
implementation derived from @maltheim’s code: RGB LED Kit for Tiny FX Tutorial? - #15 by maltheim
Then there’s some other stuff ;)
Nice, thankyou. This will give me something to tinker with this evening. =)