from BreakfastSerial import Led, Arduino, Button board = Arduino() LED_PIN = 9 LED_GREEN = 12 BUTTON_PIN = 2 led = Led(board, LED_PIN) led_green = Led(board, LED_GREEN) button = Button(board, BUTTON_PIN) def hold_cb(): print "Holding..." led.on() sleep(2) led.off() def down_cb(): led_green.on() def up_cb(): print "Up \n" button.down(down_cb) button.up(up_cb) button.hold(hold_cb) import code code.InteractiveConsole(locals=globals()).interact()
LED_2 = Led(board, LED_2) LED_3 = Led(board, LED_3) button = Button(board, BUTTON_PIN) def hold_cb(): print "Full Volume" led.on() m.setvolume(100) LED_2.off() LED_3.off() def down_cb(): LED_2.on() LED_3.on() print "Setting!" m.setvolume(20) led.off() def up_cb(): print "button up" button.down(down_cb) button.up(up_cb) button.hold(hold_cb) # Run an interactive shell so you can play (not required) import code code.InteractiveConsole(locals=globals()).interact()
#! /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()
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