本文整理汇总了Python中Arduino.Arduino.Arduino类的典型用法代码示例。如果您正苦于以下问题:Python Arduino类的具体用法?Python Arduino怎么用?Python Arduino使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Arduino类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
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()
示例2: __init__
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()
示例3: setup
def setup(self):
global obj_arduino
obj_arduino=Arduino()
self.port=obj_arduino.locateport()
obj_arduino.open_serial(1,self.port,self.baudrate)
self.obj_icm=IC_methods(self.baudrate)
示例4: __init__
class LED_ON_OFF_LOOP:
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.blue=9
self.green=10
self.red=11
for i in range(6):
self.obj_arduino.cmd_digital_out(1,self.green,1)
sleep(2)
self.obj_arduino.cmd_digital_out(1,self.green,0)
sleep(2)
def exit(self):
self.obj_arduino.close_serial()
示例5: __init__
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()
示例6: __init__
class PUSHBUTTON_LED:
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.blue=9
self.green=10
self.red=11
self.pushbutton=12
for i in range(20):
val=self.obj_arduino.cmd_digital_in(1,self.pushbutton)
#sleep(0.5)
print val
self.obj_arduino.cmd_digital_out(1,self.blue,val)
sleep(0.5)
def exit(self):
self.obj_arduino.close_serial()
示例7: __init__
class PUSHBUTTON_LED:
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.blue=9
self.green=10
self.red=11
self.pushbutton=12
l = 10 # length
x = range(l) # x axis
T = [0 for i in range(l)] # initial value
for i in range(20):
val=self.obj_arduino.cmd_digital_in(1,self.pushbutton)
#sleep(0.5)
print val
self.obj_arduino.cmd_digital_out(1,self.blue,val)
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("Is Pushbutton pressed ?")
plt.grid(True)
plt.ylabel('Pushbutton')
plt.legend(loc='upper left')
plt.axis([0, l, 0, 2])
plt.scatter(x, T, linewidth=5)
plt.draw()
plt.pause(.0001)
plt.clf()
plt.close('all')
def exit(self):
self.obj_arduino.close_serial()
示例8: __init__
class NOT_GATE:
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.ledPin=9
self.aPin=5
for _ in range(0,100):
vala=self.obj_arduino.cmd_digital_in(1,self.aPin) #Reads state of aPin and stores it in vala
print "A= "+vala
if vala=='0':
self.obj_arduino.cmd_digital_out(1,self.ledPin,1) #sets ste of output pin as HIGH
sleep(0.1)
else:
self.obj_arduino.cmd_digital_out(1,self.ledPin,0) #sets state of output pin as LOW
sleep(0.1)
def exit(self):
self.obj_arduino.close_serial()
示例9: __init__
class LED_ON_OFF:
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.blue=9
self.obj_arduino.cmd_digital_out(1,self.blue,1)
sleep(2)
self.obj_arduino.cmd_digital_out(1,self.blue,0)
sleep(2)
def exit(self):
self.obj_arduino.close_serial()
示例10: __init__
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()
示例11: __init__
class PUSHBUTTON:
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.pushbutton=12
for i in range(10):
val=self.obj_arduino.cmd_digital_in(1,self.pushbutton)
sleep(1)
print val
def exit(self):
self.obj_arduino.close_serial()
示例12: __init__
class SIPO:
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):
pinstate='0'
lastpinstate='0'
clockPin=5 # Pulse to be counted
D2='0' #serial data input, input by user is given to FF2 (MSB FF)
#output of FF2=input of FF1
D1='0' #D1=Q2, FF1 (middle bit FF), output of FF1=input of FF0
D0='0' #D0=Q1, FF0 (LSB FF), output of FF0 = Q0
Q='0' #output of FF0
#Serial input
inPin=5
#Parallel output
outPin1=9 #LSB = Q
outPin2=10 #middle bit
outPin3=11 #MSB
#external clock pulse
clockPin=2
for _ in range(0,100):
#pin 9=Q=LSB
if D0=='0':
self.obj_arduino.cmd_digital_out(1,outPin1,0)
sleep(0.1)
else:
self.obj_arduino.cmd_digital_out(1,outPin1,1)
sleep(0.1)
#pin 10=Q1=D0=middle bit
if D1=='0':
self.obj_arduino.cmd_digital_out(1,outPin2,0)
sleep(0.1)
else:
self.obj_arduino.cmd_digital_out(1,outPin2,1)
sleep(0.1)
#pin 11=Q2=D1=MSB
if D2=='0':
self.obj_arduino.cmd_digital_out(1,outPin3,0)
sleep(0.1)
else:
self.obj_arduino.cmd_digital_out(1,outPin3,1)
sleep(0.1)
#reads the state of clock
pinstate=self.obj_arduino.cmd_digital_in(1,clockPin)
#clock is common for all FFs
#thus only 1 if statement for detecting positive edge of clock
if pinstate!=lastpinstate:
if pinstate=='1':
#order of FFs: serial input-FF2-FF1-FF0
#FF0 (LSB FF, i.e. third FF)
if D0=='0':
Q='0'
else:
Q='1'
#FF1 (middle bit FF i.e. second FF)
if D1=='0':
D0='0'
else:
D0='1'
#FF2 (MSB FF i.e first FF)
if D2=='0':
D1='0'
else:
D1='1'
D2=self.obj_arduino.cmd_digital_in(1,inPin) #input is given to D of FF2 (MSB FF)
sleep(0.05)
#.........这里部分代码省略.........
示例13: __init__
class SIPO_IC:
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):
dataPin=11
clockPin=9
latchPin=10
inPin=5
for _ in range(0,100):
self.obj_arduino.cmd_digital_out(1,latchPin,0) #So that the data is stored and not passed on to the output LEDs
self.obj_arduino.cmd_shift_out_(dataPin,clockPin,inPin)
self.obj_arduino.cmd_digital_out(1,latchPin,1) #So that the stored data is now passed on to the output LEDs
#and the output is obtained
sleep(0.5)
def exit(self):
self.obj_arduino.close_serial()
示例14: __init__
class PISO:
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):
pinstate='0'
lastpinstate='0'
sl='0' #shift/!load
D2='0' #MSB input
D1='0' #middle bit input=MSB output
D0='0' #LSB input=middle bit output
Q='0' #LSB output
#Parallel inputs
inPin1=5 #LSB input
inPin2=6 #middle bit
inPin3=7 #MSB
#Serial output
outPin=9 #LSB = Q
#external clock pulse
clockPin=2
#Shift/!Load input
slPin=3
for _ in range(0,500):
#pin 9=Q=LSB output
if D0=='0':
self.obj_arduino.cmd_digital_out(1,outPin,0)
sleep(0.1)
else:
self.obj_arduino.cmd_digital_out(1,outPin,1)
sleep(0.1)
#reads the state of Shift/!Load
sl=self.obj_arduino.cmd_digital_in(1,slPin)
#reads the state of clock
pinstate=self.obj_arduino.cmd_digital_in(1,clockPin)
#clock is common for all FFs
#thus only 1 if statement for detecting positive edge of clock
if pinstate!=lastpinstate:
if pinstate=='1':
#order of FFs: serial input-FF2-FF1-FF0
if sl=='0': #parallel load mode
D0=self.obj_arduino.cmd_digital_in(1,inPin1)
D1=self.obj_arduino.cmd_digital_in(1,inPin2)
D2=self.obj_arduino.cmd_digital_in(1,inPin3)
else: #sl==1 i.e. serial shift mode
#FF0 (LSB FF, i.e. third FF)
if D0=='0':
Q='0'
else:
Q='1'
#FF1 (middle bit FF i.e. second FF)
if D1=='0':
D0='0'
else:
D0='1'
#FF2 (MSB FF i.e first FF)
if D2=='0':
D1='0'
else:
D1='1'
D2='0'
sleep(0.05)
lastpinstate=pinstate
#.........这里部分代码省略.........
示例15: __init__
class PISO_IC_p:
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)
# self.obj_icm=IC_methods(self.baudrate)
def run(self):
dataPin=9
clockPin=10
latchPin=11
ledPin=5 #LED that shows serial output
clockLed=6 #LED that shows clock pulses
p=int(raw_input("Enter no. of times parallel load is to be given: "))
self.obj_arduino.cmd_digital_out(1,latchPin,1) #parallel load mode
for _ in range(0,p):
print ("Give input, Parallel load mode:")
sleep(2)
self.obj_arduino.cmd_digital_out(1,clockPin,1) #positive edge occurs
#parallel load is stored
print("Inputs stored, Serial shift mode:")
sleep(0.5)
self.obj_arduino.cmd_digital_out(1,clockPin,0)
self.obj_arduino.cmd_digital_out(1,latchPin,0) #serial out mode
self.obj_arduino.cmd_shift_in(dataPin,clockPin,ledPin,clockLed)
self.obj_arduino.cmd_digital_out(1,latchPin,1)
self.obj_arduino.cmd_digital_out(1,ledPin,0)
def exit(self):
self.obj_arduino.close_serial()