Esempio n. 1
0
          ]
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:
                led.on()
                if dotOrDash == ".":
                    sleep(dotDelay) # dot duration
                else: # must be "-"
                    sleep(dotDelay * 3) # dash duration
                led.off()
                sleep(dotDelay) # gap between flashes
            sleep(dotDelay * 3) # gap between letters
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
0
sleep(1)

# Cyan (R: off, G: on, B: on)
led.cyan()
sleep(1)

# Purple (R: on, G: off, B: on)
led.purple()
sleep(1)

# White (R: on, G: on, B: on)
led.white()
sleep(1)

# Off (R: off, G: off, B: off)
led.off()

# Run an interactive shell so you can play (not required)
import code
code.InteractiveConsole(locals=globals()).interact()

########NEW FILE########
__FILENAME__ = servo
#! /usr/bin/env python
"""
This is an example that demonstrates how to use a
servo with BreakfastSerial. It assumes you have a 
servo wired up to pin 10.
"""
from BreakfastSerial import Arduino, Servo
from time import sleep