def action(changepin,value): setpin = changepin message = " " deviceName = pins[setpin]['name'] if value == "on" : gpio.digitalWrite(setpin,gpio.HIGH) message = "turned " + deviceName + " on." if value == "off" : gpio.digitalWrite(setpin,gpio.LOW) message = "turned " + deviceName + " off." if value == "toggle" : gpio.digitalWrite(setpin,not gpio.digitalRead(setpin)) message = "toggled " + deviceName + " ." for pin in pins: pins[pin]['state'] = gpio.digitalRead(pin) templateData = { 'message' : message , 'pins' : pins } return render_template('pin.html',**templateData)
def cool_read(): stat_y = gpio.digitalRead(cool) stat_y2 = gpio.digitalRead(cool2) if stat_y == True and stat_y2 != True: print "y" return "y" elif stat_y == True and stat_y2 == True: print "y2" return "y2"
def heat_read(): stat_w = gpio.digitalRead(heat) stat_w2 = gpio.digitalRead(heat2) if stat_w == True and stat_w2 != True: print "w" return "w" elif stat_w == True and stat_w2 == True: print "w2" return "w2"
def blinking(): """ Just testing! """ # Setup. pins_led = [18, 23, 24, 25] pin_switch_a = 17 pin_switch_b = 4 val = gpio.wiringPiSetupGpio() if val < 0: raise Exception('Problem seting up WiringPI.') # Configure GPIO pins. for pin in pins_led: gpio.pinMode(pin, gpio.OUTPUT) gpio.pinMode(pin_switch_a, gpio.INPUT) gpio.pinMode(pin_switch_b, gpio.INPUT) gpio.pullUpDnControl(pin_switch_a, gpio.PUD_DOWN) gpio.pullUpDnControl(pin_switch_b, gpio.PUD_DOWN) time_delta = 0.1 # Main loop. flag = True while flag: time.sleep(time_delta) # Read switches. val_a = gpio.digitalRead(pin_switch_a) val_b = gpio.digitalRead(pin_switch_b) if val_a: time_delta *= 1.1 print(time_delta) if val_b: time_delta *= 0.9 print(time_delta) # Set LEDs. for pin in pins_led: value_rnd = np.random.random_integers(0, 1) gpio.digitalWrite(pin, value_rnd)
def main(): for pin in pins : pins[pin]['state'] = gpio.digitalRead(pin) templateData = { 'pins':pins } return render_template('pin.html',**templateData)
def key_interrupt(): val=gpio.digitalRead(key_pin) if val==0: time.sleep(0.010) if val==0: return '1' return '0'
def key_interrupt(): val = gpio.digitalRead(key_pin) if val == 0: time.sleep(0.010) if val == 0: return '1' return '0'
def main(): for pin in pins : pins[pin]['state'] = gpio.digitalRead(pin) templateData = { 'pins':pins } #def hello_world(): #return 'Hello World!' return render_template('pin.html',**templateData)
def detectarpcduino(): while 1: A = gpio.digitalRead(sensor1) B = gpio.digitalRead(sensor2) if A == True: while B == False and y != "salir": print "ciclo 1A" B = gpio.digitalRead(sensor2) if B == True: A = False while B == True: B = gpio.digitalRead(sensor2) print "Ciclo 2A" y = "salir" global Estado Estado = True y = "" if B == True: while A == False and y != "salir": print "ciclo 1B" A = gpio.digitalRead(sensor1) if A == True: B = False while A == True: A = gpio.digitalRead(sensor1) print "Ciclo 2B" y = "salir" global Estado Estado = False print "estado1", Estado time.sleep(1)
def detectarpcduino(estado_queue, permiso_queue): while 1: A=gpio.digitalRead(sensor1) B= gpio.digitalRead(sensor2) if A==True: while B==False and y!= "salir": print "ciclo 1A (entra)" B=gpio.digitalRead(sensor2) if B==True: A=False while B==True: B=gpio.digitalRead(sensor2) print "Ciclo 2A (entra)" y= "salir" estado_queue.put(True) y="" if B==True: while A==False and y!= "salir": print "ciclo 1B" A=gpio.digitalRead(sensor1) if A==True: B=False while A==True: A=gpio.digitalRead(sensor1) print "Ciclo 2B" y= "salir" estado_queue.put(False) #print "estado1" , Estado print estado_queue.qsize() time.sleep(.1)
def readPin(pin): gpio.pinMode(channel[int(pin)],gpio.INPUT) value = " " if (gpio.digitalRead(channel[int(pin)]) == gpio.HIGH) : value = "Read GPIO" + pin + " is high !" else : value = "Read GPIO" + pin +" is low !" templateData = { 'title' : 'Status of GPIO' + pin , 'value' : value } return render_template('pin.html',**templateData)
def status(): message = "Controller Status Page" #get relay states for relay in relays: relays[relay]['state'] = gpio.digitalRead(relay) temp = ctl.temperature humi = ctl.humidity templateData = { 'message' : message , 'temp' : temp, 'humi' : humi, 'relays' : relays, 'uptime' : GetUptime() } return render_template('status.html',**templateData)
def status(): message = "Controller Status Page" #get relay states for relay in relays: relays[relay]['state'] = gpio.digitalRead(relay) #get sensor data #dht22.setup() #dht22.getth() temp = dht22.cvar.temperature humi = dht22.cvar.humidity templateData = { 'message' : message , 'temp' : temp, 'humi' : humi, 'relays' : relays } return render_template('status.html',**templateData)
def home(): message = "Controller Status Page" #get relay states for relay in relays: relays[relay]['state'] = gpio.digitalRead(relay) #get sensor data #dht22.setup() #dht22.getth() temp = ctl.temperature humi = ctl.humidity templateData = { 'message' : message , 'temp' : temp, 'humi' : humi, 'relays' : relays, 'uptime' : GetUptime() } return render_template('temptest1.html',**templateData)
def detectarpcduino(estado_queue, permiso_queue): estado_queue.put(None) while 1: A=gpio.digitalRead(sensor1) B= gpio.digitalRead(sensor2) print A, B if A==True: while B==False and y!= "salir": #print "ciclo 1" B=gpio.digitalRead(sensor2) if B==True: A=False while B==True: B=gpio.digitalRead(sensor2) #print "Ciclo 2" y= "salir" estado_queue.put("entra") y="" if B==True: while A==False and y!= "salir": #print "ciclo 1" A=gpio.digitalRead(sensor1) if A==True: B=False while A==True: A=gpio.digitalRead(sensor1) #Sprint "Ciclo 2" y= "salir" estado_queue.put("sale") time.sleep(.1)
def detectarpcduino(estado_queue, permiso_queue): while 1: rojo = "gpio6" verde = "gpio7" alarma= "gpio8" gpio.pinMode(rojo, gpio.OUTPUT) gpio.pinMode(verde, gpio.OUTPUT) gpio.pinMode(alarma, gpio.OUTPUT) A=gpio.digitalRead(sensor1) B= gpio.digitalRead(sensor2) estado= False if A==True: while B==False and y!= "salir": print "Escalon 1A (Persona entra)" B=gpio.digitalRead(sensor2) if B==True: A=False while B==True: B=gpio.digitalRead(sensor2) print "Escalon 2A (Persona entra)" y= "salir" estado=True y="" if B==True: while A==False and y!= "salir": print "Escalon 1B (Persona sale)" A=gpio.digitalRead(sensor1) if A==True: B=False while A==True: A=gpio.digitalRead(sensor1) print "Escalon 2B (Persona sale)" y= "salir" estado=False ################### VERIFICA PERMISO DE ENTRADA Permiso=permiso_queue.get() permiso_queue.put(Permiso) print "La lectura de entradas es: ", estado print "el permiso de entrar es: ", Permiso print "tamaño", permiso_queue.qsize() if estado==False and Permiso== False: gpio.digitalWrite(alarma, gpio.LOW) gpio.digitalWrite(rojo, gpio.LOW) gpio.digitalWrite(verde, gpio.LOW) print "alarma, rojo y verde apagados" if estado==False and Permiso== True: gpio.digitalWrite(verde, gpio.HIGH) print "verde prendido" if estado==True and Permiso== False: gpio.digitalWrite(alarma, gpio.HIGH) gpio.digitalWrite(rojo, gpio.HIGH) print "Rojo y alarma prendidos.. delay" time.sleep(3) estado=False permiso_queue.get() permiso_queue.put(False) if estado==True and Permiso== True: time.sleep(.2) estado=False permiso_queue.get() permiso_queue.put(False) time.sleep(.05)
for face in faces: print "Face at: " + str(face.coordinates()) myFace = face.crop() noses = myFace.findHaarFeatures('nose') if noses: nose = noses.sortArea()[-1] print "Nose at: " + str(nose.coordinates()) xmust = face.points[0][0] + nose.x - (stache.width/2) ymust = face.points[0][1] + nose.y + (stache.height/3) else: return frame frame = frame.blit(stache, pos=(xmust, ymust), mask=stacheMask) return frame else: return frame while not myDisplay.isDone(): inputValue = gpio.digitalRead("gpio13") frame = myCamera.getImage() if inputValue == True: frame = frame.blit(stache, pos=(0,0), mask=stache) #frame = mustachify(frame) frame.save("photo-" + str(time()) + ".jpg") frame = frame.flipHorizontal() frame.show() sleep(3) else: frame = frame.flipHorizontal() frame.save(myDisplay) sleep(.05)
import gpio import time gpio.pinMode(171, 'out') gpio.pinMode(189, 'in') while(True): gpio.digitalWrite(171,gpio.digitalRead(189))
import gpio import time # Put a led with positive leg in p8_3 and negative pin in p8_1 gpio.pinMode("P8_3",gpio.OUTPUT) gpio.pinMode("P8_4",gpio.INPUT) gpio.digitalWrite("P8_3",gpio.HIGH) #Now your led are lighting val = gpio.digitalRead("P8_4") # If P8_4 is connected with P8_3 val = 1 print val time.sleep(1) #To turn off your led gpio.digitalWrite("P8_3",gpio.LOW) val = gpio.digitalRead("P8_4") # If P8_4 is connected with P8_3 val = 0 print val
#Run this python script like : # python motion_detector.py ### detect camera import argparse import datetime import time import cv2 import gpio btn_pin = "gpio0" gpio.pinMode(btn_pin, gpio.INPUT) camera = cv2.VideoCapture(0) time.sleep(0.25) while True: current_st = gpio.digitalRead(btn_pin) (grabbed, frame) = camera.read() if not grabbed: break cv2.putText(frame, datetime.datetime.now().strftime("%A %d %B %Y %I:%M:%S%p"), (10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1) cv2.imshow("video", frame) next_st = gpio.digitalRead(btn_pin) if current_st ^ next_st: name = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
def fan_read(): stat_g = gpio.digitalRead(fan) if stat_g == True: print "g" return "g"
def reversingValve(): stat_o = gpio.digitalRead(reversing) if stat_o == True: print "o/b" return "o"
def digitalRead(self, pin_no): return gpio.digitalRead(self.getPin(pin_no))
def detectarpcduino(estado_queue, permiso_queue): while 1: rojo = "gpio6" verde = "gpio7" alarma = "gpio8" gpio.pinMode(rojo, gpio.OUTPUT) gpio.pinMode(verde, gpio.OUTPUT) gpio.pinMode(alarma, gpio.OUTPUT) A = gpio.digitalRead(sensor1) B = gpio.digitalRead(sensor2) estado = False if A == True: while B == False and y != "salir": print "Escalon 1A (Persona entra)" B = gpio.digitalRead(sensor2) if B == True: A = False while B == True: B = gpio.digitalRead(sensor2) print "Escalon 2A (Persona entra)" y = "salir" estado = True y = "" if B == True: while A == False and y != "salir": print "Escalon 1B (Persona sale)" A = gpio.digitalRead(sensor1) if A == True: B = False while A == True: A = gpio.digitalRead(sensor1) print "Escalon 2B (Persona sale)" y = "salir" estado = False ################### VERIFICA PERMISO DE ENTRADA Permiso = permiso_queue.get() permiso_queue.put(Permiso) print "La lectura de entradas es: ", estado print "el permiso de entrar es: ", Permiso print "tamaño", permiso_queue.qsize() if estado == False and Permiso == False: gpio.digitalWrite(alarma, gpio.LOW) gpio.digitalWrite(rojo, gpio.LOW) gpio.digitalWrite(verde, gpio.LOW) print "alarma, rojo y verde apagados" if estado == False and Permiso == True: gpio.digitalWrite(verde, gpio.HIGH) print "verde prendido" if estado == True and Permiso == False: gpio.digitalWrite(alarma, gpio.HIGH) gpio.digitalWrite(rojo, gpio.HIGH) print "Rojo y alarma prendidos.. delay" time.sleep(3) estado = False permiso_queue.get() permiso_queue.put(False) if estado == True and Permiso == True: time.sleep(.2) estado = False permiso_queue.get() permiso_queue.put(False) time.sleep(.05)
import gpio import time # Put a led with positive leg in p8_3 and negative pin in p8_1 gpio.pinMode("P8_3", gpio.OUTPUT) gpio.pinMode("P8_4", gpio.INPUT) gpio.digitalWrite("P8_3", gpio.HIGH) #Now your led are lighting val = gpio.digitalRead("P8_4") # If P8_4 is connected with P8_3 val = 1 print val time.sleep(1) #To turn off your led gpio.digitalWrite("P8_3", gpio.LOW) val = gpio.digitalRead("P8_4") # If P8_4 is connected with P8_3 val = 0 print val