grove.grove_ryb_led_button
¶
- This is the code for
Examples
from grove.button import Button
import grove.grove_ryb_led_button.GroveLedButton
import time
# slot/gpio number your device plugin
pin = 12
obj = GroveLedButton(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¶
GroveLedButton
: Grove Red/Yellow/Blue Led Button class
- class grove.grove_ryb_led_button.GroveLedButton(pin)[source]¶
Grove Red/Yellow/Blue Led Button class
all of them has a gpio button with low valid level of pressing, and a gpio led with high valid level for lighting.
- Parameters:
pin (int) – the number of gpio/slot your grove device connected.
Inheritance
digraph inheritance902116b6e1 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "GroveLedButton" [URL="#grove.grove_ryb_led_button.GroveLedButton",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 Red/Yellow/Blue Led Button 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