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


Python Arduino.close方法代码示例

本文整理汇总了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:
开发者ID:Merlin-ua,项目名称:iteaser,代码行数:33,代码来源:test2.py

示例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. ")
开发者ID:danustc,项目名称:Behavior,代码行数:104,代码来源:LED_para.py

示例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()
开发者ID:danr94,项目名称:Behavior,代码行数:5,代码来源:Arduino_chip.py

示例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)

开发者ID:cap10subtext,项目名称:PingCanal,代码行数:31,代码来源:sample_blink.py

示例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()
""" 

开发者ID:dmanfly,项目名称:geecon2015,代码行数:30,代码来源:slave_with_servo.py


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