grove.grove_mech_keycap
¶
- This code is for
which is a mechanical switch with a build-in LED. The 255 full color RGB LED makes it simple and easy to show the statues of your switch.
Examples
from grove.button import Button
import grove.grove_mech_keycap.GroveKeycap
import time
# slot/gpio number your device plugin
pin = 12
obj = GroveKeycap(pin)
# the default behavior of led is
# single click - on
# double click - blink
# long press - off
# remove ''' pairs below to begin your experiment
'''
# define a customized event handle your self
def cust_on_event(index, event, tm):
# obj.led could be used to operate led
print("event with code {}, time {}".format(event, tm))
obj.on_event = cust_on_event
'''
while True:
time.sleep(1)
Classes¶
GroveKeycap
: Grove Mech Keycap class
- class grove.grove_mech_keycap.GroveKeycap(pin)[source]¶
Grove Mech Keycap class
- Parameters:
pin (int) – the number of gpio/slot your grove device connected. for RPi, only 12 or 18 are acceptable.
Inheritance
digraph inheritancea3eb7fa02a { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "GroveKeycap" [URL="#grove.grove_mech_keycap.GroveKeycap",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Grove Mech Keycap class"]; }- property on_event¶
- Property access with
- callback – a callable function/object,
will be called when there is button event
- callback prototype:
callback(index, code, time)
- callback argument:
- Args:
index(int): button index, be in 0 to [button count - 1]
- code (int): bits combination of
Button.EV_LEVEL_CHANGED
Button.EV_SINGLE_CLICK
Button.EV_DOUBLE_CLICK
Button.EV_LONG_PRESS
time(time): event generation time
Returns: none
Examples
set
obj.on_event = callback
get
callobj = obj.on_event