本文整理汇总了Python中arduino.Arduino.getState方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.getState方法的具体用法?Python Arduino.getState怎么用?Python Arduino.getState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.getState方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Arduino
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import getState [as 别名]
from arduino import Arduino
import time
b = Arduino('COM4')
pin = 5
#declare output pins as a list/tuple
b.output([pin])
for i in range(10):
b.setHigh(pin)
print b.getState(pin)
time.sleep(1)
b.setLow(pin)
print b.getState(pin)
time.sleep(1)
b.close()
示例2: main
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import getState [as 别名]
def main():
global board
global firstWireCut
board = Arduino("/dev/cu.usbmodem1411")
log("experiment type: " + experimentType)
startTime = time.time()
# declare output pins as a list/tuple
# these correspond to the 3 different LED colors for the eyes
# board.output([14])
# board.output([10])
board.output([9, 10, 11])
# board.on9()
# board.on10()
# board.on11()
# board.output([10])
# board.analogWrite(10,0)
# board.output([10])
# time.sleep(2)
# board.output([10])
# board.analogWrite(10, 10)
# can set any of those as high/low using
# board.setHigh(9)
# board.setLow(9)
# obviously switch number for pin it corresponds to
# 2 through 6 correspond to the white wires
# 15 to 19 are the black wires (on the breadboard)
wirePins = [2, 3, 4, 5, 6, 15, 16, 17, 18, 19]
# wirePins = [6]
goodWires = 5 # number of good wires remaining
badWires = 5 # number of good wires remaining
# load robot speech recordings (none of these exist yet obviously)
recordings = {
"2": "2.wav",
"3": "3.wav",
"4": "4.wav",
"5": "5.wav",
"6": "6.wav",
"15": "15.wav",
"16": "16.wav",
"17": "17.wav",
"18": "18.wav",
"19": "19.wav",
}
try: # need this to close the log file
while True:
# ellapsedSeconds(startTime)
# play the intro sounds
# firstWireCut = False
if not firstWireCut and ellapsedSeconds(startTime) % 20 == 0:
playIntroSound()
for pin in wirePins:
state = board.getState(pin) # this is either true/false
# true = high (uncut wire), false = low (cut)
if state == False: # this wire was cut
firstWireCut = True # mark that a wire has been cut
# remove from pins
wirePins.remove(pin)
# see if its a good wire or bad wire and
# call the appropriate function
if pin <= 6:
goodWires -= 1
onGoodWireCut(goodWires)
else:
badWires -= 1
onBadWireCut(badWires)
except (KeyboardInterrupt, SystemExit):
f.close()
示例3: Arduino
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import getState [as 别名]
b = Arduino('/dev/ttyACM0')
print "Connected to ttyACM0"
except:
b = Arduino('/dev/ttyUSB0')
print "Connected to ttyUSB0"
led_pin = 13
b.output([led_pin])
b.input([])
b.servos([])
print "Pin setup done"
for i in xrange(18):
b.setHigh(led_pin)
time.sleep(1)
print b.getState(led_pin)
b.setLow(led_pin)
print b.getState(led_pin)
time.sleep(1)
#servo1 = 13
#servo2 = 12
#b.output([])
#b.input([])
#b.servos([servo1, servo2])
# for i in xrange(18):
# # b.setHigh(pin)
# # time.sleep(1)
# # print b.getState(pin)