Пример #1
0
    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)
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
0
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()
Пример #4
0
    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)
Пример #5
0
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()
Пример #6
0
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()
Пример #7
0
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()
Пример #8
0
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()
Пример #9
0
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()
Пример #10
0
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()
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()
Пример #12
0
class TEST_FIRMWARE:
    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):
        

    def exit(self):
        self.obj_arduino.close_serial()

def main():
    obj_led=TEST_FIRMWARE(115200)

if __name__== '__main__':
    main()
Пример #13
0
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()
Пример #14
0
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()
Пример #15
0
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()
Пример #16
0
    def __init__(self, test=Constants.test, parent=None):
        # UI init
        super(MainWindow, self).__init__(parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.voltageTimer = QTimer()
        self.voltageTimer.start(
            Constants.updateRate)  # update every 0.15 second
        self.guiTimer = QTimer()
        self.guiTimer.start(0)
        self.cm = plt.get_cmap('cool')
        self.alarm = Alarm(Constants.alarmParams, parent=self)
        self.judge = Judge(Constants.DATA_DIR)
        self.warning = Warning(parent=self)
        self.recorder = None
        self.setting = Setting(self.alarm.getInitialState())
        self.time = None
        self.measure = None
        self.predict = {'predict': 1, 'cnt': 0, 'curr_predict': None}

        # check it is test mode or not (arduino don't need to connect)
        try:
            self.arduino = Arduino()
        except:
            print('using monk arduino')
            self.arduino = ArduinoTest()

        # Connection
        self.voltageTimer.timeout.connect(self.voltageUpdate)
        self.ui.actionRecord_Data.triggered.connect(self.recordData)
        self.ui.actionSetting.triggered.connect(self.showSetting)
        self.setting.finished.connect(self.settingClose)
        self.guiTimer.timeout.connect(self.guiUpdate)

        # ShortCut
        self.ui.actionRecord_Data.setShortcut("Ctrl+D")
        self.ui.actionSetting.setShortcut("Ctrl+S")

        # Check is there are the data valid or not
        self.judgeStatusCheck()

        # Show the main window
        self.show()

        # Show and locate the warning message manually
        self.warning.showWarning()
Пример #17
0
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(10):
            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()
Пример #18
0
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()
Пример #19
0
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()
Пример #20
0
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()
Пример #21
0
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

        for i in range(20):
            val = self.obj_arduino.cmd_analog_in(1, self.therm)
            print val
            sleep(0.5)

    def exit(self):
        self.obj_arduino.close_serial()
Пример #22
0
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()
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()
Пример #24
0
class DCMOTOR_ROTATION:
	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.pin2=10
		self.obj_arduino.cmd_dcmotor_setup(1,3,1,self.pin1,self.pin2)
		self.obj_arduino.cmd_dcmotor_run(1,1,100)
		sleep(2)
		self.obj_arduino.cmd_dcmotor_release(1,1)
		
		
			

	def exit(self):
		self.obj_arduino.close_serial()
Пример #25
0
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'

                sleep(0.05)
            lastpinstate = pinstate

    def exit(self):
        self.obj_arduino.close_serial()
Пример #26
0
class XNOR_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, 1)  # sets state of output pin as HIGH
                sleep(0.1)
            elif vala == "1" and valb == "1":
                self.obj_arduino.cmd_digital_out(1, self.ledPin, 1)
                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()
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()
Пример #28
0
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()
Пример #29
0
class JK_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.J='0'
        self.K='0'

        self.S='0'
        self.R='1'

        self.jPin=5
        self.kPin=6

        self.prePin=3
        self.clrPin=4

        #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) #Gives low output at Q
                self.obj_arduino.cmd_digital_out(1,self.qbarPin,1) #Gives high output at Qbar
                sleep(0.1)
            else:
                self.obj_arduino.cmd_digital_out(1,self.qPin,1) #Gives high output at Q
                self.obj_arduino.cmd_digital_out(1,self.qbarPin,0) #Gives low output at Qbar
                sleep(0.1)


            self.pre=self.obj_arduino.cmd_digital_in(1,self.prePin) #Reads preset input
            self.clr=self.obj_arduino.cmd_digital_in(1,self.clrPin) #Reads clear input

            if self.pre=='0' and self.clr=='1':
                self.S='1'
                self.R='0'
                self.Q='1'
                
            elif self.pre=='1' and self.clr=='0':
                self.S='0'
                self.R='1'
                self.Q='0'

            #Normal functioning when both are HIGH
            elif self.pre=='1' and self.clr=='1':
                
                self.pinstate=self.obj_arduino.cmd_digital_in(1,self.clockPin) #Reads clock input

                if self.pinstate!=self.lastpinstate: #edge detection
                    if self.pinstate=='1': #Positive edge

                        #MASTER
                        #JK FF Code
                        self.J=self.obj_arduino.cmd_digital_in(1,self.jPin)
                        self.K=self.obj_arduino.cmd_digital_in(1,self.kPin)

                        if self.J=='0' and self.K=='1':
                            self.S='0'
                            self.R='1'
                        elif self.J=='1' and self.K=='0':
                            self.S='1'
                            self.R='0'
                        elif self.J=='1' and self.K=='1':
                            temp=self.S
                            self.S=self.R
                            self.R=temp
                        else:
                            pass
                    else:
                        pass

                    if self.pinstate=='0':

                        #SLAVE
                        #JK FF code only for state 01 and 10
                        if self.S=='0' and self.R=='1':
                            self.Q='0'
                        elif self.S=='1' and self.R=='0':
                            self.Q='1'
                        else:
                            pass
                    else:
                        pass

                    sleep(0.05)
                self.lastpinstate=self.pinstate
            else:
                pass
    


    def exit(self):
        self.obj_arduino.close_serial()
Пример #30
0
class SERVO_INIT:
	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.obj_arduino.cmd_servo_attach(1,1)
		self.obj_arduino.cmd_servo_move(1,1,30)
		sleep(1)
		self.obj_arduino.cmd_servo_detach(1,1)
		sleep(1)
		
		
			

	def exit(self):
		self.obj_arduino.close_serial()
Пример #31
0
class D_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.D='0'
        
        self.dPin=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.D=self.obj_arduino.cmd_digital_in(1,self.dPin) #Reads input D
                    

                    if self.D=='0':
                        self.Q='0'
                    
                    else:
                        self.Q='1'

                sleep(0.05)
            self.lastpinstate=self.pinstate
                







    def exit(self):
        self.obj_arduino.close_serial()
Пример #32
0
 def setup(self):
     #self.baudrate = baudrate
     self.obj_arduino = Arduino()
     self.port = self.obj_arduino.locateport()
     #Open Serial PORT
     self.obj_arduino.open_serial(1, self.port, self.baudrate)
Пример #33
0
class MUX:
    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  #Output

        #select lines
        self.aPin = 6  #input A (MSB)
        self.bPin = 7  #input B (LSB)

        #inputs
        self.Pin4 = 5  #input 4 (MSB)
        self.Pin3 = 4  #input 3
        self.Pin2 = 3  #input 2
        self.Pin1 = 2  #input 1 (LSB)

        for _ in range(0, 200):
            i4 = self.obj_arduino.cmd_digital_in(1, self.Pin4)  #MSB input
            i3 = self.obj_arduino.cmd_digital_in(1, self.Pin3)
            i2 = self.obj_arduino.cmd_digital_in(1, self.Pin2)
            i1 = self.obj_arduino.cmd_digital_in(1, self.Pin1)  #LSB input

            A = self.obj_arduino.cmd_digital_in(
                1, self.aPin)  #MSB select line input
            B = self.obj_arduino.cmd_digital_in(
                1, self.bPin)  #LSB select line input

            if A == '0' and B == '0':
                #input i1 is selected, output is same as i1
                if i1 == '0':
                    self.obj_arduino.cmd_digital_out(1, self.ledPin, 0)
                    sleep(0.1)
                else:
                    self.obj_arduino.cmd_digital_out(1, self.ledPin, 1)
                    sleep(0.1)

            elif A == '0' and B == '1':
                #input i2 is selected, output is same as i2
                if i2 == '0':
                    self.obj_arduino.cmd_digital_out(1, self.ledPin, 0)
                    sleep(0.1)
                else:
                    self.obj_arduino.cmd_digital_out(1, self.ledPin, 1)
                    sleep(0.1)

            elif A == '1' and B == '0':
                #input i3 is selected, output is same as i3
                if i3 == '0':
                    self.obj_arduino.cmd_digital_out(1, self.ledPin, 0)
                    sleep(0.1)
                else:
                    self.obj_arduino.cmd_digital_out(1, self.ledPin, 1)
                    sleep(0.1)

            elif A == '1' and B == '1':
                #input i4 is selected, output is same as i4
                if i4 == '0':
                    self.obj_arduino.cmd_digital_out(1, self.ledPin, 0)
                    sleep(0.1)
                else:
                    self.obj_arduino.cmd_digital_out(1, self.ledPin, 1)
                    sleep(0.1)

            else:
                print("Invalid input!")

    def exit(self):
        self.obj_arduino.close_serial()
Пример #34
0
 def setup(self):
     #self.baudrate = baudrate
     self.obj_arduino = Arduino()
     self.port = self.obj_arduino.locateport()
     #Open Serial PORT
     self.obj_arduino.open_serial(1, self.port,self.baudrate)
Пример #35
0
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)
            lastpinstate = pinstate

    def exit(self):
        self.obj_arduino.close_serial()
Пример #36
0
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
        data=[0 for _ in range(0,8)] #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(dataPin,clockPin,'LSBFIRST',data)
            self.obj_arduino.cmd_digital_out(1,latchPin,1)
            sleep(0.5)
            for k in range(0,7):
                data[7-k]=data[6-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()
Пример #37
0
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)
            lastpinstate=pinstate
                    
                    
            



    def exit(self):
        self.obj_arduino.close_serial()
Пример #38
0
class SERVO_INIT:
    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.obj_arduino.cmd_servo_attach(1, 1)
        self.obj_arduino.cmd_servo_move(1, 1, 30)
        sleep(1)
        self.obj_arduino.cmd_servo_detach(1, 1)
        sleep(1)

    def exit(self):
        self.obj_arduino.close_serial()
Пример #39
0
class DCMOTOR_ROTATION:
	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.pin2=10
		self.obj_arduino.cmd_dcmotor_setup(1,3,1,self.pin1,self.pin2)
		self.obj_arduino.cmd_dcmotor_run(1,1,100)
		sleep(2)
		self.obj_arduino.cmd_dcmotor_release(1,1)
		
		
			

	def exit(self):
		self.obj_arduino.close_serial()
Пример #40
0
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'

                    
                sleep(0.05)
            lastpinstate=pinstate
                    
                    
            



    def exit(self):
        self.obj_arduino.close_serial()
Пример #41
0
class DEMUX:

    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.inPin=5 #Input

        #select lines        
        self.aPin=6 #input A (MSB)
        self.bPin=7 #input B (LSB)

        #outputs
        self.ledPin4=11 #output 4 (MSB)
        self.ledPin3=10 #output 3
        self.ledPin2=9 #output 2
        self.ledPin1=8 #output 1 (LSB)
        
        
        for _ in range(0,500):
             i=self.obj_arduino.cmd_digital_in(1,self.inPin) #input
             

             A=self.obj_arduino.cmd_digital_in(1,self.aPin) #MSB select line input
             B=self.obj_arduino.cmd_digital_in(1,self.bPin) #LSB select line input

             print ("A= "+A+", B= "+B+", i= "+i)
            
                    
             if i=='0': #all outputs will be zero irrespective of which one is selected
                 self.obj_arduino.cmd_digital_out(1,self.ledPin1,0)
                 self.obj_arduino.cmd_digital_out(1,self.ledPin2,0)
                 self.obj_arduino.cmd_digital_out(1,self.ledPin3,0)
                 self.obj_arduino.cmd_digital_out(1,self.ledPin4,0)
                 sleep(0.1)
                     

             elif i=='1': 
                 if A=='0' and B=='0': #input i is seen at first output pin (LSB)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin1,1)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin2,0)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin3,0)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin4,0)
                     sleep(0.1)
                     
                 elif A=='0' and B=='1': #input i is seen at second output pin
                     self.obj_arduino.cmd_digital_out(1,self.ledPin2,1)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin1,0)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin3,0)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin4,0)
                     sleep(0.1)
                     
                 elif A=='1' and B=='0': #input i is seen at third output pin
                     self.obj_arduino.cmd_digital_out(1,self.ledPin3,1)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin1,0)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin2,0)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin4,0)
                     sleep(0.1)
                     
                 elif A=='1' and B=='1': #input i is seen at fourth output pin (MSB)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin4,1)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin1,0)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin2,0)
                     self.obj_arduino.cmd_digital_out(1,self.ledPin3,0)
                     sleep(0.1)

                 

    def exit(self):
        self.obj_arduino.close_serial()
Пример #42
0
class D_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.D='0'
        
        self.dPin=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.D=self.obj_arduino.cmd_digital_in(1,self.dPin) #Reads input D

                if self.D=='0':
                    self.Q='0'
                else:
                    self.Q='1'
                


    def exit(self):
        self.obj_arduino.close_serial()
Пример #43
0
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()
Пример #44
0
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()
Пример #45
0
from picamera.array import PiRGBArray
from picamera import PiCamera
from fase2 import fase2
from time import sleep
import cv2
import numpy as np
import atexit
"""import subprocess
from crash_watchdog.file.file import File
from crash_watchdog.file.crash_watchdog import check_state<<
stat_storage = File()
path_stat_file = r'{}'.format(os.getcwd()+"/"+os.path.basename(__file__))"""
#subprocess.call("raspivid -t 999999 -h 720 -w 1080 -fps 30 -hf -vf -b 2000000 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! queue ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host= port=5000")

from Arduino.Arduino import Arduino
arduino = Arduino(baudrate=9600, timeout=1)
ret = arduino.setup(port=0)

arduino.write("Is90F")
arduino.write("Im0&0F")
#Line following & camera variables
rango_reescalar = 4
last_line_position = 0
black = 0
white = 255
parametro_threshold = 90
#Cantidad minima de pixeles rojos en la linea para considerarlo un cuadro rojo
min_red_pixels = 20
delta_red = 50
camera = PiCamera()
camera.rotation = 180
Пример #46
0
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
                    
                    
            



    def exit(self):
        self.obj_arduino.close_serial()
class D2B:

    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):
        
        #binary Outputs
        self.led1=10 #LSB
        self.led2=11 #middle bit
        self.led3=12 #MSB

        #decimal inputs
        self.Pin1=2 #decimal input 1 (LSB)
        self.Pin2=3 #decimal input 2
        self.Pin3=4 #decimal input 3
        self.Pin4=5 #decimal input 4 
        self.Pin5=6 #decimal input 5
        self.Pin6=7 #decimal input 6
        self.Pin7=8 #decimal input 7 (MSB)
        
        
        for _ in range(0,500):
                       
            d1=self.obj_arduino.cmd_digital_in(1,self.Pin1)
            d2=self.obj_arduino.cmd_digital_in(1,self.Pin2)
            d3=self.obj_arduino.cmd_digital_in(1,self.Pin3)
            d4=self.obj_arduino.cmd_digital_in(1,self.Pin4)
            d5=self.obj_arduino.cmd_digital_in(1,self.Pin5)
            d6=self.obj_arduino.cmd_digital_in(1,self.Pin6)
            d7=self.obj_arduino.cmd_digital_in(1,self.Pin7)

            print (d1+" "+d2+" "+d3+" "+d4+" "+d5+" "+d6+" "+d7)

            #decimal input 0, binary output 000
            if d1=='0' and d2=='0' and d3=='0' and d4=='0' and d5=='0' and d6=='0' and d7=='0':
                self.obj_arduino.cmd_digital_out(1,self.led1,0)
                self.obj_arduino.cmd_digital_out(1,self.led2,0)
                self.obj_arduino.cmd_digital_out(1,self.led3,0)
                sleep(0.1)
                
            #decimal input 1, binary output 001
            elif d1=='1' and d2=='0' and d3=='0' and d4=='0' and d5=='0' and d6=='0' and d7=='0':
                self.obj_arduino.cmd_digital_out(1,self.led1,1)
                self.obj_arduino.cmd_digital_out(1,self.led2,0)
                self.obj_arduino.cmd_digital_out(1,self.led3,0)
                sleep(0.1)
            #decimal input 2, binary output 010
            elif d2=='1' and d3=='0' and d4=='0' and d5=='0' and d6=='0' and d7=='0':
                self.obj_arduino.cmd_digital_out(1,self.led1,0)
                self.obj_arduino.cmd_digital_out(1,self.led2,1)
                self.obj_arduino.cmd_digital_out(1,self.led3,0)
                sleep(0.1)
            #decimal input 3, binary output 011
            elif d3=='1' and d4=='0' and d5=='0' and d6=='0' and d7=='0':
                self.obj_arduino.cmd_digital_out(1,self.led1,1)
                self.obj_arduino.cmd_digital_out(1,self.led2,1)
                self.obj_arduino.cmd_digital_out(1,self.led3,0)
                sleep(0.1)
            #decimal input 4, binary output 100
            elif d4=='1' and d5=='0' and d6=='0' and d7=='0':
                self.obj_arduino.cmd_digital_out(1,self.led1,0)
                self.obj_arduino.cmd_digital_out(1,self.led2,0)
                self.obj_arduino.cmd_digital_out(1,self.led3,1)
                sleep(0.1)
            #decimal input 5, binary output 101
            elif d5=='1' and d6=='0' and d7=='0':
                self.obj_arduino.cmd_digital_out(1,self.led1,1)
                self.obj_arduino.cmd_digital_out(1,self.led2,0)
                self.obj_arduino.cmd_digital_out(1,self.led3,1)
                sleep(0.1)
            #decimal input 6, binary output 110
            elif d6=='1' and d7=='0':
                self.obj_arduino.cmd_digital_out(1,self.led1,0)
                self.obj_arduino.cmd_digital_out(1,self.led2,1)
                self.obj_arduino.cmd_digital_out(1,self.led3,1)
                sleep(0.1)
            #decimal input 7, binary output 111
            elif d7=='1':
                self.obj_arduino.cmd_digital_out(1,self.led1,1)
                self.obj_arduino.cmd_digital_out(1,self.led2,1)
                self.obj_arduino.cmd_digital_out(1,self.led3,1)
                sleep(0.1)
            else:
                self.obj_arduino.cmd_digital_out(1,self.led1,0)
                self.obj_arduino.cmd_digital_out(1,self.led2,0)
                self.obj_arduino.cmd_digital_out(1,self.led3,0)
                sleep(0.1)
             

       


    def exit(self):
        self.obj_arduino.close_serial()
Пример #48
0
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()
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()
Пример #50
0
class JK_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.J = '0'
        self.K = '0'

        self.jPin = 5
        self.kPin = 6

        self.prePin = 3
        self.clrPin = 4

        #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
                sleep(0.05)
            elif self.Q == '1':
                self.obj_arduino.cmd_digital_out(1, self.qPin,
                                                 1)  #Gives high output at Q
                sleep(0.05)
            else:
                pass

            if self.Qbar == '0':
                self.obj_arduino.cmd_digital_out(1, self.qbarPin,
                                                 0)  #Gives low output at Qbar
                sleep(0.05)
            elif self.Qbar == '1':
                self.obj_arduino.cmd_digital_out(1, self.qbarPin,
                                                 1)  #Gives high output at Qbar
                sleep(0.05)
            else:
                pass

            self.J = self.obj_arduino.cmd_digital_in(
                1, self.jPin)  #Reads the input J
            self.K = self.obj_arduino.cmd_digital_in(
                1, self.kPin)  #Reads the input K

            self.pre = self.obj_arduino.cmd_digital_in(
                1, self.prePin)  #Reads the input Preset
            self.clr = self.obj_arduino.cmd_digital_in(
                1, self.clrPin)  #Reads the input Clear

            if self.pre == '0' and self.clr == '1':
                self.Q = '1'
                self.Qbar = '0'

            elif self.pre == '1' and self.clr == '0':
                self.Q = '0'
                self.Qbar = '1'

            #Preset and clear are active low inputs, thus normal functioning of flip flop happens when both are HIGH
            elif self.pre == '1' and self.clr == '1':
                if self.obj_arduino.cmd_digital_in(1, self.clockPin) == '1':

                    if self.J == '0' and self.K == '1':
                        self.Q = '0'
                        self.Qbar = '1'
                    elif self.J == '1' and self.K == '0':
                        self.Q = '1'
                        self.Qbar = '0'
                    elif self.J == '1' and self.K == '1':  #toggle state
                        temp = self.Q
                        self.Q = self.Qbar
                        self.Qbar = temp
                    else:
                        pass

    def exit(self):
        self.obj_arduino.close_serial()
Пример #51
0
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()
Пример #52
0
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
        for i in range(20):
            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(2)
                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(2)
                self.obj_arduino.cmd_digital_out(1, self.green, 0)
            else:
                self.obj_arduino.cmd_digital_out(1, self.red, 1)
                sleep(2)
                self.obj_arduino.cmd_digital_out(1, self.red, 0)

    def exit(self):
        self.obj_arduino.close_serial()
 def setup(self):
     self.obj_arduino=Arduino()
     self.port=self.obj_arduino.locateport()
     self.obj_arduino.open_serial(1,self.port,self.baudrate)
Пример #54
0
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()
Пример #55
0
 def setup(self):
     self.obj_arduino = Arduino()
     self.port = self.obj_arduino.locateport()
     self.obj_arduino.open_serial(1, self.port, self.baudrate)
Пример #56
0
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()