Exemplo n.º 1
0
#! /usr/bin/env python
"""
This is an example that demonstrates how to blink an
led using BreakfastSerial.  It assumes you have an
led wired up to pin 13.
"""
from BreakfastSerial import Led, Arduino

board = Arduino()
led = Led(board, 13)

led.blink(200)

# Run an interactive shell so you can play (not required)
import code
code.InteractiveConsole(locals=globals()).interact()
Exemplo n.º 2
0
#! /usr/bin/env python
"""
This is an example that demonstrates how to use a
button to control an led with BreakfastSerial. It
assumes you have an button wired up to pin 8 and an
led wired to pin 13.
"""
from BreakfastSerial import Arduino, Led, Button

board = Arduino()
button = Button(board, 8)
led = Led(board, 13)

button.down(led.toggle)
button.hold(lambda: led.blink(200))

# Run an interactive shell so you can play (not required)
import code
code.InteractiveConsole(locals=globals()).interact()
Exemplo n.º 3
0
led13 = Led(board, 13)
ledg = Led(board, 9)
ledr = Led(board, 10)
btn = Button(board, 2)

def btn_up_cb():
    ledg.off()
    ledr.off()

def btn_down_cb():
    ledg.on()
    ledr.off()

def btn_hold_cb():
    ledg.blink(200)
    second = datetime.datetime.now().second
    print("Current second: {}".format(second))
    bspeed = second * 1000 / 60
    ledr.blink(bspeed)

if __name__=="__main__":
    btn.up(btn_up_cb)
    btn.down(btn_down_cb)
    btn.hold(btn_hold_cb)

    led13.blink(1000)
    print("Ready.")
    print("Press ctrl + c to quit.")
    while True:
        pass