本文整理汇总了Python中Arduino.Arduino.Arduino.cmd_digital_in方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.cmd_digital_in方法的具体用法?Python Arduino.cmd_digital_in怎么用?Python Arduino.cmd_digital_in使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arduino.Arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.cmd_digital_in方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
class T_FF:
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.T='0'
self.tPin=5
#assuming initial state:
self.Q='0'
self.Qbar='1'
self.qPin=9
self.qbarPin=10
self.clockPin=2 #external clock
for _ in range(0,500):
if self.Q=='0':
self.obj_arduino.cmd_digital_out(1,self.qPin,0)
self.obj_arduino.cmd_digital_out(1,self.qbarPin,1)
sleep(0.1)
else:
self.obj_arduino.cmd_digital_out(1,self.qPin,1)
self.obj_arduino.cmd_digital_out(1,self.qbarPin,0)
sleep(0.1)
if self.obj_arduino.cmd_digital_in(1,self.clockPin)=='1': #Reads clock and executes when it is HIGH
self.T=self.obj_arduino.cmd_digital_in(1,self.tPin) #Reads input T
if self.T=='1':
temp=self.Q
self.Q=self.Qbar
self.Qbar=temp
else:
pass
def exit(self):
self.obj_arduino.close_serial()
示例2: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
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()
示例3: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
class XOR_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
self.bPin=6
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
#print type(vala)
#sleep(0.1)
valb=self.obj_arduino.cmd_digital_in(1,self.bPin) #Reads state of bPin and stores it in valb
print "B= "+valb
#print type(valb)
#sleep(0.1)
if vala=='0' and valb=='0':
self.obj_arduino.cmd_digital_out(1,self.ledPin,0) #sets state of output pin as LOW
sleep(0.1)
elif vala=='1' and valb=='1':
self.obj_arduino.cmd_digital_out(1,self.ledPin,0)
sleep(0.1)
else:
self.obj_arduino.cmd_digital_out(1,self.ledPin,1) #sets state of output pin as HIGH
sleep(0.1)
def exit(self):
self.obj_arduino.close_serial()
示例4: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
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):
pinstate=0
n=int(raw_input("Enter no. of bits: "))
data=[0 for _ in range(0,n)] #an 8-elements list representing an 8 bit binary number
dataPin=11
clockPin=9
latchPin=10
inPin=5
for _ in range(0,50):
pinstate=self.obj_arduino.cmd_digital_in(1,inPin)
if pinstate=='1':
data[0]=1
#the msb becomes 1 when input is given
#high which is henceforth shifted
else:
data[0]=0
print data
self.obj_arduino.cmd_digital_out(1,latchPin,0)
self.obj_arduino.cmd_shift_out_n(dataPin,clockPin,'LSBFIRST',data,n)
self.obj_arduino.cmd_digital_out(1,latchPin,1)
sleep(0.5)
for k in range(0,(n-1)):
data[(n-1)-k]=data[(n-2)-k]
data[0]=0
#every element of the matrix is
#shifted one place to the right
#so effectively the 8 bit
#binary number is divided by 2
def exit(self):
self.obj_arduino.close_serial()
示例5: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
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()
示例6: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
class SENSE:
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):
jlast=0
k=0
j=0
self.pin1=9
self.pin2=10
self.intrp=5
ilast=self.obj_arduino.cmd_digital_in(1,self.intrp)
self.obj_arduino.cmd_dcmotor_setup(1,3,1,self.pin1,self.pin2) # Initialize motor of the interrupt
for s in range(5000):
self.obj_arduino.cmd_dcmotor_run(1,1,100) # Rotate the motor
i=self.obj_arduino.cmd_digital_in(1,self.intrp) # Read the signal of the receiver of IR sensor
if i!=ilast: # Check whether the motor is rotating
if i=='1': # Condition when the receiver receives the signal from transmitter
j=j+1
sleep(0.01)
ilast=i
if j!=jlast:
print j
if j%17==0 and j!=0: # Condition for one complete rotation
k=k+1 # No of rotations
print 'number of rotations completed are',k
jlast=j
self.obj_arduino.cmd_dcmotor_release(1,1)
def exit(self):
self.obj_arduino.close_serial()
示例7: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
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()
示例8: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
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)
#.........这里部分代码省略.........
示例9: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
class SR_FF:
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.S='0'
self.R='0'
self.sPin=5 #Input S is given to Pin 5
self.rPin=6 #Input R is given to Pin 6
#assuming initial state:
self.Q='0'
self.Qbar='1'
self.qPin=9
self.qbarPin=10
self.clockPin=2 #external clock
for _ in range(0,500):
if self.Q=='0':
self.obj_arduino.cmd_digital_out(1,self.qPin,0) #Gives low output at Q
elif self.Q=='1':
self.obj_arduino.cmd_digital_out(1,self.qPin,1) #Gives high output at Q
else:
pass
sleep(0.1)
if self.Qbar=='0':
self.obj_arduino.cmd_digital_out(1,self.qbarPin,0) #Gives low output at Qbar
elif self.Qbar=='1':
self.obj_arduino.cmd_digital_out(1,self.qbarPin,1) #Gives high output at Qbar
else:
pass
sleep(0.1)
self.S=self.obj_arduino.cmd_digital_in(1,self.sPin) #Reads the input S
self.R=self.obj_arduino.cmd_digital_in(1,self.rPin) #Reads the input R
if self.obj_arduino.cmd_digital_in(1,self.clockPin)=='1':
if self.S=='0' and self.R=='1':
self.Q='0'
self.Qbar='1'
elif self.S=='1' and self.R=='0':
self.Q='1'
self.Qbar='0'
elif self.S=='1' and self.R=='1': #we assume this case doesn't occur
self.Q='0'
self.Qbar='0'
else:
pass
def exit(self):
self.obj_arduino.close_serial()
示例10: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
class T_FF_edge:
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.T = "0"
self.tPin = 5
# assuming initial state:
self.Q = "0"
self.Qbar = "1"
self.qPin = 9
self.qbarPin = 10
self.clockPin = 2 # external clock
self.pinstate = "0"
self.lastpinstate = "0"
for _ in range(0, 500):
if self.Q == "0":
self.obj_arduino.cmd_digital_out(1, self.qPin, 0)
self.obj_arduino.cmd_digital_out(1, self.qbarPin, 1)
sleep(0.1)
else:
self.obj_arduino.cmd_digital_out(1, self.qPin, 1)
self.obj_arduino.cmd_digital_out(1, self.qbarPin, 0)
sleep(0.1)
self.pinstate = self.obj_arduino.cmd_digital_in(1, self.clockPin) # Reads clock
if self.pinstate != self.lastpinstate: # Edge detection
if self.pinstate == "0": # negative edge
self.T = self.obj_arduino.cmd_digital_in(1, self.tPin) # Reads input T
if self.T == "1":
temp = self.Q
self.Q = self.Qbar
self.Qbar = temp
else:
pass
sleep(0.05)
self.lastpinstate = self.pinstate
def exit(self):
self.obj_arduino.close_serial()
示例11: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
class PIPO:
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'
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
#Parallel output
outPin1=9 #LSB = Q
outPin2=10 #middle bit = D0
outPin3=11 #MSB = D1
#external clock pulse
clockPin=2
for _ in range(0,100):
#pin 9=Q=LSB output
if Q=='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 output
if D0=='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 output
if D1=='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
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)
#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'
#.........这里部分代码省略.........
示例12: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
class COUNTER_wo_ff:
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
#outputs
Pin1=9 #LSB
Pin2=10 #middle bit
Pin3=11 #MSB
i=0
a=0
b=0
c=0
for _ in range(0,500):
pinstate=self.obj_arduino.cmd_digital_in(1,clockPin)
#negative edge of clock pulse to FF1
if pinstate!=lastpinstate:
if pinstate=='0':
i+=1
else:
pass
sleep(0.05)
else:
pass
lastpinstate=pinstate
a=i%2
b=(i/2)%2
c=(i/4)%2
self.obj_arduino.cmd_digital_out(1,Pin1,a) #LSB
self.obj_arduino.cmd_digital_out(1,Pin2,b) #middle bit
self.obj_arduino.cmd_digital_out(1,Pin3,c) #MSB
sleep(0.1)
if i>7:
i=0
else:
pass
def exit(self):
self.obj_arduino.close_serial()
示例13: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
class SR_FF_edge:
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.S='0'
self.R='0'
self.sPin=5 #Input S is given to Pin 5
self.rPin=6 #Input R is given to Pin 6
#assuming initial state:
self.Q='0'
self.Qbar='1'
self.qPin=9
self.qbarPin=10
self.clockPin=2 #external clock
self.pinstate='0'
self.lastpinstate='0'
for _ in range(0,500): #Runs the program 500 times in a loop
if self.Q=='0':
self.obj_arduino.cmd_digital_out(1,self.qPin,0) #Gives low output at Q
elif self.Q=='1':
self.obj_arduino.cmd_digital_out(1,self.qPin,1) #Gives high output at Q
sleep(0.1)
else:
pass
if self.Qbar=='0':
self.obj_arduino.cmd_digital_out(1,self.qbarPin,0) #Gives low output at Qbar
elif self.Qbar=='1':
self.obj_arduino.cmd_digital_out(1,self.qbarPin,1) #Gives high output at Qbar
sleep(0.1)
else:
pass
self.pinstate=self.obj_arduino.cmd_digital_in(1,self.clockPin)
if self.pinstate!=self.lastpinstate: #edge detection
if(self.pinstate=='0'): #negative edge
self.S=self.obj_arduino.cmd_digital_in(1,self.sPin) #Reads the input S
self.R=self.obj_arduino.cmd_digital_in(1,self.rPin) #Reads the input R
if self.S=='0' and self.R=='1':
self.Q='0'
self.Qbar='1'
elif self.S=='1' and self.R=='0':
self.Q='1'
self.Qbar='0'
elif self.S=='1' and self.R=='1': #we assume this case doesn't occur
self.Q='0'
self.Qbar='0'
else:
pass
sleep(0.05)
self.lastpinstate=self.pinstate
def exit(self):
self.obj_arduino.close_serial()
示例14: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
class SUBTRACTER:
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.diffPin=9 #Difference
self.boutPin=10 #Borrow out
self.aPin=5 #input A
self.bPin=6 #input B
self.binPin=3 #input Bin (Borrow in)
for _ in range(0,100):
vala=self.obj_arduino.cmd_digital_in(1,self.aPin)
print "A= "+vala
valb=self.obj_arduino.cmd_digital_in(1,self.bPin)
print "B= "+valb
valbin=self.obj_arduino.cmd_digital_in(1,self.binPin)
print "Bin= "+valbin
#As acoording to the logic circuit of full subtracter
#First half subtracter
#Difference
#A XOR B
if vala=='0' and valb=='0':
fsdiff='0'
elif vala=='1' and valb=='1':
fsdiff='0'
else:
fsdiff='1'
#borrow out
#A NOT
if vala=='1':
fsnot='0'
else:
fsnot='1'
#B AND fsnot
if valb=='1' and fsnot=='1':
fsb='1'
else:
fsb='0'
#second half subtacter
#difference
#fsdiff XOR Bin
if fsdiff=='0' and valbin=='0':
self.obj_arduino.cmd_digital_out(1,self.diffPin,0)
sleep(0.1)
elif fsdiff=='1' and valbin=='1':
self.obj_arduino.cmd_digital_out(1,self.diffPin,0)
sleep(0.1)
else:
self.obj_arduino.cmd_digital_out(1,self.diffPin,1)
sleep(0.1)
#borrow out
#fsdiff NOT
if fsdiff=='1':
ssnot='0'
else:
ssnot='1'
#Bin and ssnot
if valbin=='1' and ssnot=='1':
ssand='1'
else:
ssand='0'
#ssand OR fsb
if ssand=='0' and fsb=='0':
self.obj_arduino.cmd_digital_out(1,self.boutPin,0)
sleep(0.1)
else:
self.obj_arduino.cmd_digital_out(1,self.boutPin,1)
sleep(0.1)
def exit(self):
self.obj_arduino.close_serial()
示例15: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_in [as 别名]
class ADDER:
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.sumPin=9 #Sum
self.coutPin=10 #Carry out
self.aPin=5 #input A
self.bPin=6 #input B
self.cPin=3 #input Cin (Caryy in)
for _ in range(0,100):
vala=self.obj_arduino.cmd_digital_in(1,self.aPin)
print "A= "+vala
valb=self.obj_arduino.cmd_digital_in(1,self.bPin)
print "B= "+valb
valc=self.obj_arduino.cmd_digital_in(1,self.cPin)
print "Cin= "+valc
#As acoording to the logic circuit of full adder
#to get Pi: A XOR B
if vala=='0' and valb=='0':
P='0'
elif vala=='1' and valb=='1':
P='0'
else:
P='1'
#to get Gi: A AND B
if vala=='1' and valb=='1':
G='1'
else:
G='0'
#to get Sum: Pi XOR Cin
if P=='0' and valc=='0':
self.obj_arduino.cmd_digital_out(1,self.sumPin,0)
sleep(0.1)
elif P=='1' and valc=='1':
self.obj_arduino.cmd_digital_out(1,self.sumPin,0)
sleep(0.1)
else:
self.obj_arduino.cmd_digital_out(1,self.sumPin,1)
sleep(0.1)
#To get Carry out
#Pi AND Cin
if P=='1' and valc=='1':
temp='1'
else:
temp='0'
# Gi OR temp
if G=='0' and temp=='0':
self.obj_arduino.cmd_digital_out(1,self.coutPin,0)
sleep(0.1)
else:
self.obj_arduino.cmd_digital_out(1,self.coutPin,1)
sleep(0.1)
def exit(self):
self.obj_arduino.close_serial()