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


Python Arduino.cmd_digital_out方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [as 别名]
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()
开发者ID:ankushbansal3103,项目名称:pyarduino,代码行数:27,代码来源:4.4LED.py

示例2: __init__

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

        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()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:35,代码来源:SIPO_2.py

示例3: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [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()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:28,代码来源:5.2pushbutton.py

示例4: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [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()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:30,代码来源:6.2LDR.py

示例5: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [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()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:32,代码来源:9.2THERM-BUZZER.py

示例6: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [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()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:55,代码来源:SIPO_n_bits.py

示例7: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [as 别名]
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()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:55,代码来源:PISO_p_times.py

示例8: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [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()
开发者ID:ankushbansal3103,项目名称:pyarduino,代码行数:53,代码来源:5.2pushbuttonplot.py

示例9: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [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()
开发者ID:ankushbansal3103,项目名称:pyarduino,代码行数:53,代码来源:6.2LDRplot.py

示例10: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [as 别名]
class LED_ON_OFF_MULTICOLOR:

    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.obj_arduino.cmd_digital_out(1,self.blue,self.baudrate)
        self.obj_arduino.cmd_digital_out(1,self.red,self.baudrate)
        sleep(5)
        self.obj_arduino.cmd_digital_out(1,self.blue,0)
        sleep(3)
        self.obj_arduino.cmd_digital_out(1,self.red,0)

    def exit(self):
        self.obj_arduino.close_serial()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:29,代码来源:4.3LED.py

示例11: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [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()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:59,代码来源:T+FF+level.py

示例12: __init__

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

    def exit(self):
        self.obj_arduino.close_serial()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:20,代码来源:4.1LED.py

示例13: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [as 别名]
class NAND_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=='1' and valb=='1':
                 self.obj_arduino.cmd_digital_out(1,self.ledPin,0) #sets state of output pin as LOW
                 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()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:44,代码来源:NAND.py

示例14: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [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()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:68,代码来源:Counter+without+ff.py

示例15: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_digital_out [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()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:83,代码来源:Full+Adder.py


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