Giter Club home page Giter Club logo

keybow-python's Introduction

Keybow

3 and 12 key, backlit mechanical keyboard add-ons for the Raspberry Pi

Build Status Coverage Status PyPi Package Python Versions

Installing

Stable library from PyPi

Enable SPI:

sudo raspi-config nonint do_spi 0

Install the library:

python3 -m pip install keybow

You may need to use sudo (or optionally python in lieu of python3)

Latest/development library from GitHub:

  • git clone https://github.com/pimoroni/keybow-python
  • cd keybow-python
  • sudo ./install.sh

API

@keybow.on() Detect Keypress

Decorator 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 #index
  • state: 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 LEDs

Parameters:

  • 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 #index
  • r, 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 LEDs

Turn 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

Key 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

keybow-python's People

Contributors

gadgetoid avatar oiyouyeahyou avatar sandyjmacdonald avatar wildestpixel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.