当前位置: 首页>>代码示例>>Python>>正文


Python PyMata.set_analog_latch方法代码示例

本文整理汇总了Python中PyMata.pymata.PyMata.set_analog_latch方法的典型用法代码示例。如果您正苦于以下问题:Python PyMata.set_analog_latch方法的具体用法?Python PyMata.set_analog_latch怎么用?Python PyMata.set_analog_latch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyMata.pymata.PyMata的用法示例。


在下文中一共展示了PyMata.set_analog_latch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1:

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import set_analog_latch [as 别名]
# Refresh, Retrieve and print Arduino Firmware version information
firmata.refresh_report_firmware()
print firmata.get_firmata_version()

# Print PyMata's version number
print firmata.get_pymata_version()

# Setup pin A2 for input
firmata.set_pin_mode(POTENTIOMETER, firmata.INPUT, firmata.ANALOG)

# Setup pin pin 12 for the switch
firmata.set_pin_mode(BUTTON_SWITCH, firmata.INPUT, firmata.DIGITAL)

# Arm pin A2 for latching a value >= 678
firmata.set_analog_latch(POTENTIOMETER, firmata.ANALOG_LATCH_GTE, 678)

# Arm pin 12 for latching when the pin goes high
firmata.set_digital_latch(BUTTON_SWITCH, firmata.DIGITAL_LATCH_HIGH)

print "start waiting"
# wait for 5 seconds to allow user interaction with switch and pot
# during this time press and release the switch and turn the pot to maximum

time.sleep(5)

print 'end waiting'
# get and print the digital latched data
print firmata.get_digital_latch_data(BUTTON_SWITCH)

# get and print the analog data latched data
开发者ID:Haobot,项目名称:PyMata,代码行数:32,代码来源:pymata_software_data_latch.py

示例2: signal_handler

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import set_analog_latch [as 别名]
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)

# set pin modes
board.set_pin_mode(GREEN_LED, board.OUTPUT, board.DIGITAL)
board.set_pin_mode(RED_LED, board.PWM, board.DIGITAL)
board.set_pin_mode(PUSH_BUTTON, board.INPUT, board.DIGITAL)
board.set_pin_mode(POTENTIOMETER, board.INPUT, board.ANALOG)
board.set_analog_latch(POTENTIOMETER, board.ANALOG_LATCH_GTE, 1000)


# do nothing loop - program exits when latch data event occurs for potentiometer
while 1:
    count += 1
    if count == 300:
        print('bye bye')
        board.close()
    analog = board.analog_read(POTENTIOMETER)
    board.analog_write(RED_LED, analog // 4)

    digital = board.digital_read(PUSH_BUTTON)
    board.digital_write(GREEN_LED, digital)
    latch = board.get_analog_latch_data(POTENTIOMETER)
    if latch[1] == board.LATCH_LATCHED:
开发者ID:apptronics,项目名称:PyMata,代码行数:32,代码来源:polling_digital_analog_io.py

示例3: __init__

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import set_analog_latch [as 别名]
class Mqtt_Pymata:
    def __init__(self,  name, broker, port, keepalive, state_topic, command_topic, qos, retain,
                 payload_on, payload_off, optimistic, value_template,serial_port,switch_pin):
        self._switch_pin = switch_pin
        self._board = PyMata(serial_port,False,verbose=True)
        self._board.set_pin_mode(self._switch_pin,self._board.OUTPUT,self._board.DIGITAL)

        A0 = 7
        def pin_callback(data):
            print("Analog Data: ",
                  " Pin: ", data[PIN_NUMBER],
                  " Pin Mode: ", data[PIN_MODE],
                  " Data Value: ", data[DATA_VALUE])
            self._board.set_analog_latch(A0,self._board.ANALOG_LATCH_GT,500,pin_callback)


        # self._board.set_pin_mode(A0, self._board.INPUT, self._board.ANALOG)
        # self._board.set_sampling_interval(100)
        # self._board.set_analog_latch(A0,self._board.ANALOG_LATCH_GT,500,pin_callback)

        # while True:
        #     time.sleep(0.1)
        #     value = self._board.analog_read(A0)
        #     print(value)

        self._mqtt = mqtt.Client()

        self._switch = None
        self._state_topic = state_topic
        self._command_topic = command_topic
        self._qos = qos
        self._retain = retain
        self._payload_on = payload_on
        self._payload_off = payload_off
        self._optimistic = optimistic
        self._state = False

        def on_message( _mqtt, userdata, msg):
            topic = msg.topic,
            qos = msg.qos,
            payload = msg.payload.decode('utf-8'),
            payload = payload[0]
            print(msg.topic+" "+payload)

            if payload == payload_on:
                self.turn_on()
            elif payload == payload_off:
                self.turn_off()

        self._mqtt.on_message = on_message
        self._mqtt.connect(broker, port, keepalive)
        self._mqtt.subscribe(command_topic,qos)
        self._mqtt.loop_forever()

    def turn_on(self):
        self._state = True
        self.apply_state()
        self.report_state()

    def turn_off(self):
        self._state = False
        self.apply_state()
        self.report_state()

    def apply_state(self):
        self._board.digital_write(self._switch_pin,self._board.HIGH if self._state else self._board.LOW)

    def report_state(self):
        self._mqtt.publish( self._state_topic, self._payload_on if self._state else self._payload_off,
                     self._qos, self._retain)
开发者ID:zwb800,项目名称:home-assistant,代码行数:72,代码来源:mqtt_pymata.py

示例4: PyMata

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import set_analog_latch [as 别名]
        time.gmtime(data[LATCH_TIME_STAMP]))))
    # shut things down
    board.close()

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


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)

# set pin modes
board.set_pin_mode(GREEN_LED, board.OUTPUT, board.DIGITAL)
board.set_pin_mode(RED_LED, board.PWM, board.DIGITAL)
board.set_pin_mode(PUSH_BUTTON, board.INPUT, board.DIGITAL, cb_push_button)
board.set_pin_mode(POTENTIOMETER, board.INPUT, board.ANALOG, cb_potentiometer)

# set the latch
board.set_analog_latch(POTENTIOMETER, board.ANALOG_LATCH_GTE, 1000, cb_potentiometer_latch)

# do nothing loop - program exits when latch data event occurs for potentiometer or timer expires
time.sleep(15)
print('Timer expired')
board.close()
开发者ID:apptronics,项目名称:PyMata,代码行数:32,代码来源:callback_digital_analog_io.py

示例5: signal_handler

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import set_analog_latch [as 别名]

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


signal.signal(signal.SIGINT, signal_handler)

# set digital pin 13 to be an output port
firmata.set_pin_mode(BOARD_LED, firmata.OUTPUT, firmata.DIGITAL)

firmata.set_pin_mode(BOARD_BAT, firmata.INPUT, firmata.ANALOG)
firmata.set_analog_latch(BOARD_BAT, firmata.ANALOG_LATCH_GTE, 1000)

time.sleep(5)
print("Blinking LED on pin 13")

#  blink for 10 times
for x in range(10):
    print(x + 1)
    firmata.digital_write(BOARD_LED, 1)
    #  wait a half second between toggles.
    time.sleep(0.2)
    firmata.digital_write(BOARD_LED, 0)
    time.sleep(0.2)

while 1:
    count += 1
开发者ID:DarfieldChris,项目名称:MinePi,代码行数:32,代码来源:test2.py


注:本文中的PyMata.pymata.PyMata.set_analog_latch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。