Example #1
0
    def __init__(self, board, pins):
        if not board:
            raise ArduinoNotSuppliedException

        # TODO: Check that pins is dict

        super(RGBLed, self).__init__()

        self._red = Led(board, pins["red"])
        self._green = Led(board, pins["green"])
        self._blue = Led(board, pins["blue"])
Example #2
0
    def __init__(self, board, pins):
        if not board:
            raise ArduinoNotSuppliedException

        # TODO: Check that pins is dict

        super(RGBLed, self).__init__()

        self._red = Led(board, pins["red"])
        self._green = Led(board, pins["green"])
        self._blue = Led(board, pins["blue"])
Example #3
0
import settings
import sys

from BreakfastSerial import Led, Arduino, Button
from twilio import TwilioRestException
from twilio.rest import TwilioRestClient

board = Arduino()
LED_PIN = 13
BUTTON_PIN = 2

led = Led(board, LED_PIN)
button = Button(board, BUTTON_PIN)

msg_sent = False

def down_press():
  global msg_sent
  print "button down"

  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)
Example #4
0
from BreakfastSerial import Arduino, Led
from time import sleep

morsePin = 13
dotDelay = 0.2

letters = [".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",    # A-I
           ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",  # J-R
           "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..",         # S-Z
          ]
numbers = ["-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----."] # digits

if __name__ == "__main__":
    board = Arduino()
    led = Led(board, morsePin)

    while(True):
        message = raw_input("Type your message ('EOF' to finish): ")
        if message == 'EOF':
            break

        for ch in message.upper():
            if ch.isalpha():
                morsech = letters[ord(ch) - ord('A')]
            elif ch.isdigit():
                morsech = numbers[ord(ch) - ord('0')]
            elif ch == " ":
                sleep(4 * dotDelay) # gab between words
                continue

            for dotOrDash in morsech:
Example #5
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()
Example #6
0
import settings
import alsaaudio
from time import sleep
from BreakfastSerial import Led, Arduino, Button

board = Arduino()
LED_PIN = 9
LED_3 = 8
LED_2 = 11
BUTTON_PIN = 2
m = alsaaudio.Mixer()
led = Led(board, LED_PIN)
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()
#! /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()
Example #8
0
class RGBLed(EventEmitter):
    def __init__(self, board, pins):
        if not board:
            raise ArduinoNotSuppliedException

        # TODO: Check that pins is dict

        super(RGBLed, self).__init__()

        self._red = Led(board, pins["red"])
        self._green = Led(board, pins["green"])
        self._blue = Led(board, pins["blue"])

    def off(self):
        self._red.off()
        self._green.off()
        self._blue.off()
        return self

    def red(self):
        self._red.on()
        self._green.off()
        self._blue.off()
        return self

    def green(self):
        self._red.off()
        self._green.on()
        self._blue.off()
        return self

    def blue(self):
        self._red.off()
        self._green.off()
        self._blue.on()
        return self

    def yellow(self):
        self._red.on()
        self._green.on()
        self._blue.off()
        return self

    def cyan(self):
        self._red.off()
        self._green.on()
        self._blue.on()
        return self

    def purple(self):
        self._red.on()
        self._green.off()
        self._blue.on()
        return self

    def white(self):
        self._red.on()
        self._green.on()
        self._blue.on()
        return self
Example #9
0
# Run an interactive shell so you can play (not required)
import code
code.InteractiveConsole(locals=globals()).interact()

########NEW FILE########
__FILENAME__ = led
#! /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()

########NEW FILE########
__FILENAME__ = light_switch
#! /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.
Example #10
0
from Tkinter import *
from BreakfastSerial import Arduino, Buzzer, Sensor, setInterval, Led
import time

board = Arduino()
led = Led(board, 12)
buzzer = Led(board, 8)


def alert():
    print "Return to base"
    led.blink(100)
    buzzer.blink(100)


def oxygenAlert():
    led.off()
    buzzer.off()
    led.on()
    #time.sleep(2)
    print "Current Oxygen level: |||||||||| 86 %"


def dangerAlert():
    led.blink(1000)
    buzzer.blink(800)
    print "Danger Approaching. Return to base"


def co2Alert():
    led.blink(1000)
Example #11
0
import settings
from BreakfastSerial import Led, Arduino, Button
board = Arduino()
led_pin = 12
led_pins2 = 13
led2 = Led(board, led_pin)

led = Led(board, led_pins2)
led.on()
print "Led %s" % led_pin
led2.on()
print "Led 2 is ON"
Example #12
0
import datetime
from BreakfastSerial import Arduino, Led, Button

board = Arduino()
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.")
Example #13
0
import settings
from BreakfastSerial import Led, Arduino, Button
board = Arduino()
led_pin = 12 
led_pins2 = 13
led2 = Led(board, led_pin)

led = Led(board, led_pins2)
led.on()
print "Led %s" % led_pin
led2.on()
print "Led 2 is ON"
Example #14
0
#! /usr/bin/env python
"""
This is an example that demonstrates how to use a
potentiometer to fade an LED with BreakfastSerial.
It assumes you have an potentiometer wired up to
pin A0 and a LED on pin 9.
"""
from BreakfastSerial import Arduino, Sensor, Led

board = Arduino()
sensor = Sensor(board, "A0")
led = Led(board, 9)


def change_led_brightness():
    led.brightness(100 * sensor.value)


sensor.change(change_led_brightness)

# Run an interactive shell so you can play (not required)
import code
code.InteractiveConsole(locals=globals()).interact()
Example #15
0
class RGBLed(EventEmitter):

    def __init__(self, board, pins):
        if not board:
            raise ArduinoNotSuppliedException

        # TODO: Check that pins is dict

        super(RGBLed, self).__init__()

        self._red = Led(board, pins["red"])
        self._green = Led(board, pins["green"])
        self._blue = Led(board, pins["blue"])

    def off(self):
        self._red.off()
        self._green.off()
        self._blue.off()
        return self

    def red(self):
        self._red.on()
        self._green.off()
        self._blue.off()
        return self

    def green(self):
        self._red.off()
        self._green.on()
        self._blue.off()
        return self

    def blue(self):
        self._red.off()
        self._green.off()
        self._blue.on()
        return self

    def yellow(self):
        self._red.on()
        self._green.on()
        self._blue.off()
        return self

    def cyan(self):
        self._red.off()
        self._green.on()
        self._blue.on()
        return self

    def purple(self):
        self._red.on()
        self._green.off()
        self._blue.on()
        return self

    def white(self):
        self._red.on()
        self._green.on()
        self._blue.on()
        return self
Example #16
0
import settings
from BreakfastSerial import Led, Arduino, Button, Servo, Sensor
import time
from time import sleep

print '''PUT ASCII ART HERE BECAUSE ASCII!!!
         '''
User = raw_input("Please select a function to test: \n")

if User == 1:
    Led()
if User == 2:
    loop()
if User == 3:
    servo()


board = Arduino()
sensor = Sensor(board, "A0")

def loop():
    value = sensor.value or 1
    value = value / 2

    print value

    sensor.on()



def servo():
Example #17
0
# Run an interactive shell so you can play (not required)
import code
code.InteractiveConsole(locals=globals()).interact()

########NEW FILE########
__FILENAME__ = led
#! /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()

########NEW FILE########
__FILENAME__ = light_switch
#! /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.