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()
if not msg_sent: # Turn on the LED to indicate we are sending the txt message! led.on() try: client = TwilioRestClient(settings.twilio_account_sid, settings.twilio_auth_token) message = client.sms.messages.create( body=message, to=phone_number, from_=settings.your_twilio_number) except TwilioRestException as e: print "Ruh-roh got an error: %s" % e led.off() sys.exit(0) print "Attempting to send message, status is: %s" % message.status msg_sent = True led.off() def up_press(): print "button up" button.down(down_press) button.up(up_press) while(not msg_sent): continue
#! /usr/bin/env python """ This is an example that demonstrates how to use a button with BreakfastSerial. It assumes you have an button wired up to pin 8. """ from BreakfastSerial import Button, Arduino board = Arduino() button = Button(board, 8) def down_cb(): print "button down" def up_cb(): print "button up" button.down(down_cb) button.up(up_cb) # Run an interactive shell so you can play (not required) import code code.InteractiveConsole(locals=globals()).interact()
if not msg_sent: # Turn on the LED to indicate we are sending the txt message! led.on() try: client = TwilioRestClient(settings.twilio_account_sid, settings.twilio_auth_token) message = client.sms.messages.create( body="Hello from Julia's rad Arduino!", to=settings.your_phone_number, from_=settings.your_twilio_number) except TwilioRestException as e: print "Ruh-roh got an error: %s" % e led.off() sys.exit(0) print "Attempting to send message, status is: %s" % message.status msg_sent = True led.off() def up_press(): print "button up" button.down(down_press) button.up(up_press) while(not msg_sent): continue
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