本文整理汇总了Python中PyMata.pymata.PyMata.encoder_config方法的典型用法代码示例。如果您正苦于以下问题:Python PyMata.encoder_config方法的具体用法?Python PyMata.encoder_config怎么用?Python PyMata.encoder_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyMata.pymata.PyMata
的用法示例。
在下文中一共展示了PyMata.encoder_config方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PyMata
# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import encoder_config [as 别名]
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
示例2: PyMata
# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import encoder_config [as 别名]
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)
示例3: encoder_callback
# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import encoder_config [as 别名]
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)