本文整理汇总了Python中arduino.Arduino.getHammer方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.getHammer方法的具体用法?Python Arduino.getHammer怎么用?Python Arduino.getHammer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.getHammer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: freeze_support
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import getHammer [as 别名]
# Два наступних рядки істотні для роботи на ОС Windows.
if __name__ == '__main__':
freeze_support()
# Об'єкт який дає доступ до API мотора та молоточків.
device = Arduino()
# Комунікаційна бібліотека ігнорує дані деякий час, тому даємо їй час на ініціалізацію.
time.sleep(0.5)
# Розпочати рух вперед. Платформа буде їхати вперед доки ми її не зупинимо.
NUM_HAMMERS = 2
state = [0] * NUM_HAMMERS
count1 = [0] * NUM_HAMMERS
count2 = [0] * NUM_HAMMERS
count3 = [0] * NUM_HAMMERS
value = [0] * NUM_HAMMERS
while True:
hammers = device.getHammer()
finished = 0
for i in range(NUM_HAMMERS):
if state[i] == 0:
value[i] = hammers[i]
state[i] = 1
count1[i] = time.time()
elif state[i] == 1:
if value[i] != hammers[i]:
count1[i] = time.time() - count1[i]
state[i] = 2
value[i] = hammers[i]
count2[i] = time.time()
elif state[i] == 2:
if value[i] != hammers[i]:
count2[i] = time.time() - count2[i]
示例2: freeze_support
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import getHammer [as 别名]
import pygame
import sys
from arduino import Arduino
from multiprocessing import freeze_support
if __name__ == '__main__':
freeze_support()
device = Arduino()
pygame.init()
pygame.display.set_mode((100, 100))
prev = pygame.time.get_ticks()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
device.close()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_f:
device.forwardMotor()
if event.key == pygame.K_b:
device.backwardMotor()
if event.type == pygame.KEYUP:
if event.key == pygame.K_f or event.key == pygame.K_b:
device.stopMotor()
cur = pygame.time.get_ticks()
if cur - prev > 1000:
prev = cur
print device.getHammer()
print '=' * 20
示例3: freeze_support
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import getHammer [as 别名]
freeze_support()
device = Arduino()
time.sleep(0.5)
position = 0
intervals = [3.0, 4.0, 3.0, 4.0, 3.0, 2.0, 2.0, 1.0, 4.0, 1.0, 5.0]
cur = 0.0
plan = []
for i in xrange(len(intervals)):
plan.append(cur + intervals[i])
cur = plan[i]
wait = False
while True:
h = device.getHammer()
if h[4] == 1:
wait = True
if wait and h[4] == 0:
break
time.sleep(0.05)
start = time.time()
device.forwardMotor()
while True:
if time.time() - start > plan[position]:
print 'reached', position, time.time() - start
if position % 2 == 0:
print 'stopping'
device.stopMotor()
else: