keybow python
1.0.0
Enable SPI:
sudo raspi-config nonint do_spi 0
Install the library:
python3 -m pip install keybowYou may need to use sudo (or optionally python in lieu of python3)
git clone https://github.com/pimoroni/keybow-pythoncd keybow-pythonsudo ./install.sh@keybow.on() Detect KeypressDecorator to attach a handler to a Keybow key. Your handler should accept an index and a state argument.
Handler callback params:
index: Integer - 0-based index of key to set the LED for, see #indexstate: Boolean - True on key down, False on release@keybow.on()
def handle_key(index, state):
print("{}: Key {} has been {}".format(
time.time(),
index,
'pressed' if state else 'released'))keybow.set_all(r, g, b) Set all LEDsParameters:
r, g, b: Integer - amount of Red, Green and Blue (0-255)keybow.set_all(0, 64, 128)
keybow.show()NOTE: Use
keybow.show()to update the LEDs actual state
keybow.set_led(index, r, g, b) Set a single led.Parameters:
index: Integer - 0-based index of key to set the LED for, see #indexr, g, b: Integer - amount of Red, Green and Blue (0-255)for x in range(4):
keybow.set_led(x, 255, 0, 0)
for x in range(4):
keybow.set_led(x + 4, 0, 255, 0)
for x in range(4):
keybow.set_led(x + 8, 0, 0, 255)
keybow.show()NOTE: Use
keybow.show()to update the LEDs actual state
keybow.clear() Clear all LEDsTurn off all LEDs
keybow.clear()
keybow.show()NOTE: Use
keybow.show()to update the LEDs actual state
keybow.show() Update LEDs Whenever setting LEDs use this to update the LED values. This needs to be used whenever you set any LED values
index With GPIO on the left, the index is mapped out as following:
9 |
10 |
11 |
6 |
7 |
8 |
3 |
4 |
5 |
0 |
1 |
2 |