Ejemplo n.º 1
0
# Import CircuitPlayground class from the circuitplayground.py in the same directory.
from circuitplayground import CircuitPlayground

# Grab the serial port from the command line parameters.
if len(sys.argv) != 2:
    print('ERROR! Must specify the serial port as command line parameter.')
    sys.exit(-1)
port = sys.argv[1]

# Connect to Circuit Playground board on specified port.
board = CircuitPlayground(port)


# Define function that will be called when data is received from the light sensor.
def light_data(data):
    # Print out the raw light sensor ADC value (data[2] holds the value).
    print('Light sensor: {0}'.format(data[2]))


# Setup Firmata to listen to light sensor analog input (A5).
# The callback function will be called whenever new data is available.
board.set_pin_mode(5, board.INPUT, board.ANALOG, light_data)

# Loop forever printing light values as they change.
print('Printing light sensor values (Ctrl-C to quit)...')
while (True):
    time.sleep(
        1)  # Do nothing and just sleep.  When data is available the callback
    # functions above will be called.
Ejemplo n.º 2
0
def right_changed(data):
    global stop_flag
    print('Right button changed!')
    stop_flag = True
    return


def left_changed(data):
    global stop_flag
    print('Left button changed!')
    stop_flag = True
    return


board.set_pin_mode(4, board.INPUT, board.DIGITAL, left_changed)
board.set_pin_mode(19, board.INPUT, board.DIGITAL, right_changed)


def crazyboard(route):
    global stop_flag
    if route == '4001170':
        board.set_pixel(1, 139, 69, 19)
        board.set_pixel(2, 139, 69, 19)
        board.set_pixel(3, 139, 69, 19)
        board.set_pixel(4, 139, 69, 19)
        board.set_pixel(5, 139, 69, 19)
        board.set_pixel(6, 139, 69, 19)
    if route == '4008432':
        board.set_pixel(1, 128, 0, 128)
        board.set_pixel(2, 128, 0, 128)
Ejemplo n.º 3
0
import time
import sys

# Import CircuitPlayground class from the circuitplayground.py in the same directory.
from circuitplayground import CircuitPlayground


# Grab the serial port from the command line parameters.
if len(sys.argv) != 2:
    print('ERROR! Must specify the serial port as command line parameter.')
    sys.exit(-1)
port = sys.argv[1]

# Connect to Circuit Playground board on specified port.
board = CircuitPlayground(port)

# Define function that will be called when data is received from the microphone.
def sound_data(data):
    # Print out the raw microphone ADC value (data[2] holds the value).
    print('Microphone: {0}'.format(data[2]))

# Setup Firmata to listen to the microphone analog input (A4):
# The callback functions will be called whenever new data is available.
board.set_pin_mode(4, board.INPUT, board.ANALOG, sound_data)

# Loop forever printing sound values as they change.
print('Printing microphone values (Ctrl-C to quit)...')
while (True):
    time.sleep(1)  # Do nothing and just sleep.  When data is available the callback
                   # functions above will be called.
Ejemplo n.º 4
0
import time
import sys

# Import CircuitPlayground class from the circuitplayground.py in the same directory.
from circuitplayground import CircuitPlayground


# Grab the serial port from the command line parameters.
if len(sys.argv) != 2:
    print('ERROR! Must specify the serial port as command line parameter.')
    sys.exit(-1)
port = sys.argv[1]

# Connect to Circuit Playground board on specified port.
board = CircuitPlayground(port)

# Define function that will be called when data is received from the light sensor.
def light_data(data):
    # Print out the raw light sensor ADC value (data[2] holds the value).
    print('Light sensor: {0}'.format(data[2]))

# Setup Firmata to listen to light sensor analog input (A5).
# The callback function will be called whenever new data is available.
board.set_pin_mode(5, board.INPUT, board.ANALOG, light_data)

# Loop forever printing light values as they change.
print('Printing light sensor values (Ctrl-C to quit)...')
while (True):
    time.sleep(1)  # Do nothing and just sleep.  When data is available the callback
                   # functions above will be called.
Ejemplo n.º 5
0
def right_changed(data):
    # Check if right button digital input is high, i.e. button is pressed.
    # Note that data[2] contains the current digital input state.
    if data[2]:
        print('Right button pressed!')
    else:
        print('Right button released!')

def switch_changed(data):
    # Check if slide switch is left (high level) or right (low/ground level).
    if data[2]:
        print('Switch is on the left!')
    else:
        print('Switch is on the right!')

# Setup Firmata to listen to button & switch changes.
# The buttons/switches on Circuit Playground use these pins:
#  - Left button = Digital pin 4
#  - Right button = Digital pin 19
#  - Switch = Digital pin 21
board.set_pin_mode(4, board.INPUT, board.DIGITAL, left_changed)
board.set_pin_mode(19, board.INPUT, board.DIGITAL, right_changed)
board.set_pin_mode(21, board.INPUT, board.DIGITAL, switch_changed)

# Loop forever waiting for buttons to be pressed or change state.
# When the button changes one of the callback functions above will be called.
print('Press the left button, right button, or slide switch (Ctrl-C to quit)...')
while (True):
    time.sleep(1)  # Do nothing and just sleep.  When changes happen the callback
                   # functions above will be called.
Ejemplo n.º 6
0
import sys

# Import CircuitPlayground class from the circuitplayground.py in the same directory.
from circuitplayground import CircuitPlayground


# Grab the serial port from the command line parameters.
#if len(sys.argv) != 2:
#    print('ERROR! Must specify the serial port as command line parameter.')
#    sys.exit(-1)
#port = sys.argv[1]
port  = "/dev/tty.usbmodem1411"

# Connect to Circuit Playground board on specified port.
board = CircuitPlayground(port)

# Define function that will be called when data is received from the microphone.
def sound_data(data):
    # Print out the raw microphone ADC value (data[2] holds the value).
    print('Microphone: {0}'.format(data[2]))

# Setup Firmata to listen to the microphone analog input (A4):
# The callback functions will be called whenever new data is available.
board.set_pin_mode(4, board.INPUT, board.ANALOG, sound_data)

# Loop forever printing sound values as they change.
print('Printing microphone values (Ctrl-C to quit)...')
while (True):
    time.sleep(1)  # Do nothing and just sleep.  When data is available the callback
                   # functions above will be called.