Welcome¶
This documentation will guide you through the methods available in the pHAT BEAT python library.
- More information - https://shop.pimoroni.com/products/phat-beat
- Get the code - https://github.com/pimoroni/phat-beat
- Get help - http://forums.pimoroni.com/c/support
At A Glance¶
Handle A Button Press¶
To handle a button press, you should use the on
method as a decorator, like so:
@phatbeat.on(phatbeat.BTN_FASTFWD)
def fastfwd(pin):
print("Fast Forward Pressed")
-
phatbeat.
on
(buttons, handler=None, repeat=True)[source] Attach a handler function to one or more buttons.
Can be used as a decorator, or optionally supplied a handler param.
Parameters: - buttons – Individual button pin or list of pins to watch
- handler – Optional handler function
- repeat – Whether the handler should be repeated if the button is held
Set A Single Pixel¶
To control the dual VU meters on your pHAT BEAT manually you need to tell each pixel what colour to be. This is done via set_pixel.
The brightness
argument is completely optional. Omit it to keep the last
brightness value set for that particular pixel.
If channel
is specified then you can set pixels 0-7 on the given channel (0-1). Otherwise it treats the pixels as one chain of 16 (0-15).
-
phatbeat.
set_pixel
(x, r, g, b, brightness=None, channel=None)[source] Set the RGB value, and optionally brightness, of a single pixel
If you don’t supply a brightness value, the last value will be kept.
Parameters: - x – The horizontal position of the pixel: 0 to 7
- r – Amount of red: 0 to 255
- g – Amount of green: 0 to 255
- b – Amount of blue: 0 to 255
- brightness – Brightness: 0.0 to 1.0 (default around 0.2)
- channel – Optionally specify which bar to set: 0 or 1
Set All Pixels¶
Sometimes you need to set all the pixels to the same colour. This convinience method does just that!
To set just one channel or the other, specify channel 0 or 1.
-
phatbeat.
set_all
(r, g, b, brightness=None, channel=None)[source] Set the RGB value and optionally brightness of all pixels
If you don’t supply a brightness value, the last value set for each pixel be kept.
Parameters: - r – Amount of red: 0 to 255
- g – Amount of green: 0 to 255
- b – Amount of blue: 0 to 255
- brightness – Brightness: 0.0 to 1.0 (default around 0.2)
- channel – Optionally specify which bar to set: 0 or 1
Show¶
None of your pixels will appear until you show()
them. This method writes
all the pixel data out to your device.
-
phatbeat.
show
()[source] Output the buffer to the displays
Clear¶
Exactly the same as calling set_all(0,0,0)
, clear sets all the pixels to black.
You must also call show()
if you want to turn the displays off.
-
phatbeat.
clear
(channel=None)[source] Clear the pixel buffer
Enable/Disable Clear On Exit¶
Sometimes you want a script that runs and quits, leaving a pattern up on the displays.
-
phatbeat.
set_clear_on_exit
(value=True)[source] Set whether the displays should be cleared upon exit
By default the displays will turn off on exit, but calling:
phatbeat.set_clear_on_exit(False)
Will ensure that it does not.
Parameters: value – True or False (default True)
Constants¶
The following constants denote available buttons for pHAT BEAT.
BTN_FASTFWD = 5
BTN_REWIND = 13
BTN_PLAYPAUSE = 6
BTN_VOLUP = 16
BTN_VOLDN = 26
BTN_ONOFF = 12
BUTTONS
list of all available buttons