本文整理汇总了Python中Arduino.Arduino.Arduino.cmd_analog_in方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.cmd_analog_in方法的具体用法?Python Arduino.cmd_analog_in怎么用?Python Arduino.cmd_analog_in使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arduino.Arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.cmd_analog_in方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_analog_in [as 别名]
class THERM_BUZZER:
def __init__(self,baudrate):
self.baudrate=baudrate
self.setup()
self.run()
self.exit()
def setup(self):
self.obj_arduino=Arduino()
self.port=self.obj_arduino.locateport()
self.obj_arduino.open_serial(1,self.port,self.baudrate)
def run(self):
self.therm=4
self.buzzer=3
for i in range(20):
val=self.obj_arduino.cmd_analog_in(1,self.therm)
print val
if (int(val) > 550):
self.obj_arduino.cmd_digital_out(1,self.buzzer,1)
else:
self.obj_arduino.cmd_digital_out(1,self.buzzer,0)
sleep(2)
def exit(self):
self.obj_arduino.close_serial()
示例2: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_analog_in [as 别名]
class SERVO_POT:
def __init__(self,baudrate):
self.baudrate=baudrate
self.setup()
self.run()
self.exit()
def setup(self):
self.obj_arduino=Arduino()
self.port=self.obj_arduino.locateport()
self.obj_arduino.open_serial(1,self.port,self.baudrate)
def run(self):
self.pin1=9
self.pot=2
self.pos=0
self.obj_arduino.cmd_servo_attach(1,1)
sleep(1)
self.angle=18
for i in range(100):
val=self.obj_arduino.cmd_analog_in(1,self.pot)
print val
val = int(val*180/1023)
print val
self.obj_arduino.cmd_servo_move(1,1,val)
sleep(0.5)
self.obj_arduino.cmd_servo_detach(1,1)
def exit(self):
self.obj_arduino.close_serial()
示例3: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_analog_in [as 别名]
class LDR:
def __init__(self,baudrate):
self.baudrate=baudrate
self.setup()
self.run()
self.exit()
def setup(self):
self.obj_arduino=Arduino()
self.port=self.obj_arduino.locateport()
self.obj_arduino.open_serial(1,self.port,self.baudrate)
def run(self):
self.ldr=5
self.blue=9
self.green=10
self.red=11
for i in range(100):
val=self.obj_arduino.cmd_analog_in(1,self.ldr)
print val
if int(val) < 300:
self.obj_arduino.cmd_digital_out(1,self.blue,1)
else:
self.obj_arduino.cmd_digital_out(1,self.blue,0)
sleep(0.5)
def exit(self):
self.obj_arduino.close_serial()
示例4: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_analog_in [as 别名]
class LDR:
def __init__(self,baudrate):
self.baudrate=baudrate
self.setup()
self.run()
self.exit()
def setup(self):
self.obj_arduino=Arduino()
self.port=self.obj_arduino.locateport()
self.obj_arduino.open_serial(1,self.port,self.baudrate)
def run(self):
self.ldr=5
self.blue=9
self.green=10
self.red=11
l = 100 # length
x = range(l) # x axis
T = [420 for i in range(l)] # initial value
for i in range(20):
val=self.obj_arduino.cmd_analog_in(1,self.ldr)
print val
if int(val) < 300:
self.obj_arduino.cmd_digital_out(1,self.blue,1)
else:
self.obj_arduino.cmd_digital_out(1,self.blue,0)
sleep(0.5)
plt.ion()
#plt.show()
t = int(val)
T.pop(0) # pop first value
T.append(t) # push at the end keeping list of same size
plt.title("Reading LDR Data from Arduino...!")
plt.grid(True)
plt.ylabel('LDR Readings')
plt.legend(loc='upper left')
plt.axis([0, l, 0.55 * min(T), 2 * max(T)])
plt.plot(x, T ,linewidth=1)
plt.draw()
plt.pause(.0001)
plt.clf()
plt.close('all')
def exit(self):
self.obj_arduino.close_serial()
示例5: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_analog_in [as 别名]
class LDR:
def __init__(self,baudrate):
self.baudrate=baudrate
self.setup()
self.run()
self.exit()
def setup(self):
self.obj_arduino=Arduino()
self.port=self.obj_arduino.locateport()
self.obj_arduino.open_serial(1,self.port,self.baudrate)
def run(self):
self.ldr=5
for i in range(100):
val=self.obj_arduino.cmd_analog_in(1,self.ldr)
print val
sleep(0.5)
def exit(self):
self.obj_arduino.close_serial()
示例6: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_analog_in [as 别名]
class SOLAR_TRACKER:
def __init__(self,baudrate):
self.baudrate=baudrate
self.setup()
self.run()
self.exit()
def setup(self):
self.obj_arduino=Arduino()
self.port=self.obj_arduino.locateport() #Locates the port
self.obj_arduino.open_serial(1,self.port,self.baudrate)
def run(self):
self.ldr1=0 #LDR1 connected at port 0
self.ldr2=1 #LDR2 connected at port 1
s=0
self.angle=5 # Step angle
self.initial=90
self.obj_arduino.cmd_servo_attach(1,1) # Attach the servo at pin 9
sleep(1)
self.obj_arduino.cmd_servo_move(1,1,self.initial) #Rotate servo by 90 deg
sleep(1)
for i in range(20):
p=self.obj_arduino.cmd_analog_in(1,self.ldr1) #Read analog input from LDR1
q=self.obj_arduino.cmd_analog_in(1,self.ldr2) # Read analog input from LDR2
print p
print q
sleep(1)
if int(p) < int(q):
s=s+1
self.obj_arduino.cmd_servo_move(1,1,90-self.angle*s) # Clockwise rotation
sleep(1)
else:
s=s-1
self.obj_arduino.cmd_servo_move(1,1,90-self.angle*s) # Anti-clockwise rotation
sleep(1)
self.obj_arduino.cmd_servo_detach(1,1) # Detach the motor
def exit(self):
self.obj_arduino.close_serial() # Close the serial port
示例7: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_analog_in [as 别名]
class POT:
def __init__(self,baudrate):
self.baudrate=baudrate
self.setup()
self.run()
self.exit()
def setup(self):
self.obj_arduino=Arduino()
self.port=self.obj_arduino.locateport()
self.obj_arduino.open_serial(1,self.port,self.baudrate)
def run(self):
self.pot=2
self.blue=9
self.green=10
self.red=11
l = 100 # length
x = range(l) # x axis
T = [420 for i in range(l)] # initial value
for i in range(35):
val=self.obj_arduino.cmd_analog_in(1,self.pot)
print val
if (int(val) >= 0 and int(val)< 320):
self.obj_arduino.cmd_digital_out(1,self.blue,1)
sleep(.25)
self.obj_arduino.cmd_digital_out(1,self.blue,0)
elif (int(val) >= 320 and int(val) < 900):
self.obj_arduino.cmd_digital_out(1,self.green,1)
sleep(.25)
self.obj_arduino.cmd_digital_out(1,self.green,0)
else:
self.obj_arduino.cmd_digital_out(1,self.red,1)
sleep(.25)
self.obj_arduino.cmd_digital_out(1,self.red,0)
plt.ion()
plt.show()
t = int(val)
T.pop(0) # pop first value
T.append(t) # push at the end keeping list of same size
plt.title("Reading Potentiometer from Arduino...!")
plt.grid(True)
plt.yticks([0,100,200,300,400,500,600,700,800,900,1000,1100])
plt.xticks([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100])
plt.ylabel('Potentiometer Readings')
plt.legend(loc='upper left')
plt.axis([0, l, 0.55 * min(T), 1.2 * max(T)])
plt.plot(x, T, linewidth=1)
plt.draw()
plt.pause(.0001)
plt.clf()
def exit(self):
self.obj_arduino.close_serial()