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


Python Arduino.setHigh方法代码示例

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


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

示例1: Arduino

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import setHigh [as 别名]
 #the blink program

#import the lib
from arduino import Arduino

import time

#specify the port as an argument
my_board = Arduino('/dev/ttyUSB0')

#declare output pins as a list/tuple
my_board.output([11,12,13])

#perform operations
i=0
while(i<10):
    my_board.setHigh(13)
    time.sleep(1)
    my_board.setLow(13)
    i+=1

开发者ID:zerohours,项目名称:ardu-mrua,代码行数:22,代码来源:test.py

示例2: __init__

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import setHigh [as 别名]
class Assay:
    # Initialize the pumps
    def __init__(self, fname, nrepeat=10, ard_port="/dev/ttyACM0", pump_port="/dev/ttyUSB0"):
        self.__observers = []  # define an observer
        self.step = -1  # before execution
        self.conf_label = "R" + "CUCI" * nrepeat
        print(self.conf_label)
        self.n_session = 1 + nrepeat * 4
        self.sessions = len(self.conf_label)  # the number of steps
        self.__construct__()
        self.time_flag = pd.Series(np.zeros(self.n_session), index=list(self.conf_label))
        ard_reset(ard_port)
        self.ard = Arduino(ard_port)
        self.ard.output([pin_LED, pin_Servo])
        self.ard.setLow(pin_LED)  # Initial
        self.fname = fname
        self.pump_init(pump_port)

    def blink_start(self, nblink=5):
        # give a blinking start, the LED blinks at 1 Hz
        for ii in range(nblink):
            self.ard.setHigh(pin_LED)
            time.sleep(0.50)
            self.ard.setLow(pin_LED)
            time.sleep(0.50)
            print(ii + 1)

        millis = int(round(time.time() * 1000))
        self.onset = millis

    def pump_init(self, pump_port):
        self.pser = serial.Serial(pump_port, 19200, timeout=0.1)
        print("connected to", self.pser.name)
        pumps = new_era.find_pumps(self.pser)
        self.pump = pumps[0]
        self.infuse = False
        new_era.set_diameter(self.pser, self.pump, dia_1ml)
        new_era.set_direct(self.pser, self.pump, 1)
        new_era.set_rate(self.pser, self.pump, flowrate)

    def register_observer(self, observer):
        self.__observers.append(observer)

    def notify_observers(self, *args, **kwargs):
        for observer in self.__observers:
            observer.notify(self, *args, **kwargs)

    def __construct__(self):
        # construct the configuration array
        self.CS_config = np.zeros([self.n_session, 4])
        ii = 0
        for ch in self.conf_label:
            if ch == "R":
                self.CS_config[ii] = CONFIG_REST
            elif ch == "C":
                self.CS_config[ii] = CONFIG_CS
            elif ch == "U":
                self.CS_config[ii] = CONFIG_US
            else:
                self.CS_config[ii] = CONFIG_INTER
            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)
#.........这里部分代码省略.........
开发者ID:danustc,项目名称:Behavior,代码行数:103,代码来源:LED_para.py

示例3: str

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import setHigh [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

示例4: Arduino

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import setHigh [as 别名]
from arduino import Arduino
import time

b = Arduino('/dev/ttyACM0')
pin1 = 1
pin2 = 2

b.output([])

while (True):
    val = b.analogRead(pin1)
    print val
    time.sleep(0.5)
if val="0":
   	b.setHigh(pin2)
else:
   	b.setLow(pin2)
   	pass
开发者ID:sherlockholmes,项目名称:serialaarduino,代码行数:20,代码来源:leer.py

示例5: xrange

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import setHigh [as 别名]
master_led_pin = 13
master_servo_pin = 12

slave_connection_pin = 11# In master
slave_led_pin = 13
slave_servo_pin = 12

#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

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

示例6: Arduino

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import setHigh [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()

开发者ID:basejumpa,项目名称:DIYPlayground,代码行数:19,代码来源:testing.py

示例7: Arduino

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import setHigh [as 别名]
except:
    try:
    	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)
开发者ID:dmanfly,项目名称:geecon2015,代码行数:33,代码来源:sample_blink.py


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