本文整理汇总了Python中arduino.Arduino.close方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.close方法的具体用法?Python Arduino.close怎么用?Python Arduino.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: freeze_support
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import close [as 别名]
import pygame
import sys
from multiprocessing import freeze_support
from arduino import Arduino
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()
elif 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 < 3000:
device.forwardMotor()
else:
device.stopMotor()
# if cur - prev > 1000:
示例2: __init__
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import close [as 别名]
#.........这里部分代码省略.........
ii += 1
# then, we need to update duration of intersessions
inter_pos = self.CS_config[:, 0] < 0 # take out the positions of intersessions, a boolean array
inter_dur = self.CS_config[inter_pos, 0]
self.CS_config[inter_pos, 0] = np.random.randint(40, 70, size=len(inter_dur))
print(self.CS_config)
self.duration = self.CS_config[:, 0].sum() / 60.0
print("Total experimental time: %4.1f min" % self.duration)
def blink(self, duration, freq=2):
# blink the LED
# duration: the duration of blinking
nblink = int(duration * freq)
thp = 1 / (freq * 2.0) # half-period
for ii in range(nblink):
self.ard.setHigh(pin_LED)
time.sleep(thp)
self.ard.setLow(pin_LED)
time.sleep(thp)
def run_step(self, sblink=False):
millis = int(round(time.time() * 1000))
self.step += 1
self.time_flag[self.step] = millis
self.notify_observers(self.step)
config_list = self.CS_config[self.step]
print(config_list[0])
# take the row
# turn on or off all the stimuli
# turn on or off the delivery
if config_list[2] == 0:
if self.infuse == True:
new_era.stop_pump(self.pser, self.pump)
self.infuse = False
elif config_list[2] == 1:
if self.infuse == False:
new_era.set_rate(self.pser, self.pump, flowrate)
new_era.run_all(self.pser)
self.infuse = True
if config_list[1] == 0:
self.ard.setLow(pin_LED) # keep the LED off
time.sleep(config_list[0])
elif config_list[1] == 1:
if sblink:
self.blink(config_list[0])
else:
self.ard.setHigh(pin_LED)
time.sleep(config_list[0])
# insert or retract the feeding tube
# if config_list[3] == 0:
# self.ard.analogWrite(pin_Servo, 0)
# elif config_list[3] == 0:
# self.ard.analogWrite(pin_Servo, 80)
# time.sleep(config_list[0])
# self.terminate_step()
def terminate_step(self):
# terminate a step
self.ard.setLow(pin_LED)
self.ard.analogWrite(pin_Servo, 0)
new_era.stop_pump(self.pser, self.pump)
def run_through(self, sblink=False):
self.blink_start()
self.step = -1
ii = 0
for ii in range(self.n_session):
self.run_step(sblink)
print("The" + str(ii) + "th session.")
# def shuffle_steps(self):
# # shuffle the steps of
# CS_total = np.inner(self.CS_config[:,0], self.CS_config[:,1]) # inner product of the first two columns, total duration of CS
# US_total = np.inner(self.CS_config[:,0], self.CS_config[:,2]) # total duration of US
# time_total = self.CS_config[:,0].sum() # The total amount of time should be equal
#
# # use 10 seconds as a unit of the
# NC_chunk = np.round(CS_total/10.).astype('int')
# NU_chunk = np.round(US_total/10.).astype('int')
# Total_chunk = np.round(time_total/10.).astype('int')
#
# shuff_LED = random_split(NC_chunk)
#
def close(self):
# destruct the class
self.ard.setLow(pin_LED)
self.ard.close()
np.save("../Data/" + self.fname, self.time_flag)
pd.Series.to_csv(self.time_flag, "../Data/" + self.fname + ".csv")
print("Arduino port closed. ")
示例3: ard_reset
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import close [as 别名]
def ard_reset(port = '/dev/ttyACM0'):
ard = Arduino(port)
ard.close()
示例4: str
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import close [as 别名]
if re.search('Arduino',str(p[1])):
portString = str(p[0])
except:
print "Could not open port!"
sys.exit()
b = Arduino(portString)
pin = (1, 2, 3, 4, 5, 6, 7, 8)
#declare output pins as a list/tuple
b.output([pin])
b.turnOff()
try:
while True:
i=0
while (i<8):
b.setHigh(pin[i])
time.sleep(.1)
b.setLow(pin[i])
time.sleep(.01)
i+=1
except KeyboardInterrupt:
while (i<8):
b.setLow(pin[i])
i+=1
b.close()
exit(0)
示例5: xrange
# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import close [as 别名]
#declare output pins as a list/tuple
b.setup([master_led_pin], [], [master_servo_pin])
#b.setup([], [], [])
b.setupSlave(0, slave_connection_pin, [slave_led_pin], [], [slave_servo_pin])
pos=1
for i in xrange(18):
b.setHigh(master_led_pin)
b.nextCommandAsSlave(0)
b.setHigh(slave_led_pin)
time.sleep(0.5)
b.setLow(master_led_pin)
b.nextCommandAsSlave(0)
b.setLow(slave_led_pin)
time.sleep(0.5)
b.nextCommandAsSlave(0)
b.setAngle(slave_servo_pin,pos)
pos +=10
print i
print pos
"""
b.setAngle(master_servo_pin, i * 10)
b.nextCommandAsSlave(0)
b.setAngle(slave_servo_pin, i * 10)
b.close()
"""