Exemplo n.º 1
0
import signal

from PyMata.pymata import PyMata

ENCODER_A = 14
ENCODER_B = 15
prev_value = 0

# create a PyMata instance
board = PyMata("/dev/ttyACM0")


def signal_handler(sig, frame):
    print('You pressed Ctrl+C!!!!')
    if board is not None:
        board.reset()
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)

# configure the pins for the encoder
board.encoder_config(ENCODER_B, ENCODER_A)

while 1:
    value = board.digital_read(ENCODER_B)
    if value != prev_value:
        prev_value = value
        print(board.digital_read(ENCODER_B))
    pass
Exemplo n.º 2
0
import sys
import signal

from PyMata.pymata import PyMata

ENCODER_A = 2
ENCODER_B = 4
prev_value = 0

# create a PyMata instance
board = PyMata("/dev/ttyACM0")


def signal_handler(sig, frame):
    print('You pressed Ctrl+C!!!!')
    if board is not None:
        board.reset()
    sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)

# configure the pins for the encoder
board.encoder_config(ENCODER_B, ENCODER_A)

while 1:
    value = board.digital_read(ENCODER_B)
    if value != prev_value:
        prev_value = value
        print(board.digital_read(ENCODER_B))
    pass
Exemplo n.º 3
0
This example illustrates using callbacks for digital and analog input.

Monitor the current analog input and digital input of two pins.
"""

import signal
import sys
import time


from PyMata.pymata import PyMata


# Instantiate PyMata
board = PyMata("/dev/ttyACM0", verbose=True)

board.encoder_config(7,2)

# Set up pin modes for both pins with callbacks for each
board.set_pin_mode(5, board.PWM, board.DIGITAL)
board.set_pin_mode(6, board.PWM, board.DIGITAL)

board.analog_write(5, 255)
board.analog_write(6, 0)

time.sleep(2)
count = board.digital_read(2)
print count
time.sleep(2)
board.analog_write(5, 0)
ENCODER_A = 14
ENCODER_B = 15

# Indices into callback return data list
DEVICE = 0
PIN = 1
DATA = 2


def encoder_callback(data):
    print("Data = %d" % data[DATA])

# create a PyMata instance
board = PyMata("/dev/ttyACM0")


def signal_handler(sig, frame):
    print('You pressed Ctrl+C!!!!')
    if board is not None:
        board.reset()
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)

# configure the pins for the encoder
board.encoder_config(ENCODER_B, ENCODER_A, encoder_callback)

while 1:
    time.sleep(.2)