def alertN(self): for i in range (2): GPIO.output(self.buz,1) time.sleep(0.5) GPIO.output(self.buz,0) time.sleep(0.5) return
def __new__(cls, port, consigne = 0): #Initialisation du nouveau moteur if port in cls._MOTEURS: #Si le port est déjà pris raise MoteurExistErreur if port not in Moteur._PORTS: #Si le port est dispo raise MoteurPortErreur if consigne < -100 or consigne > 100: #Si la vitesse est comprise dans [-100;100] raise MoteurConsigneError self = object.__new__(cls) self._port = port self._isRuning = False self._consigne = consigne cls._MOTEURS[port] = self if port == 'A': pinA = 33 pinB = 35 self._pinTacho1 = 7 self._pinTAcho2 = 11 elif port == 'B': pinA = 37 pinB = 40 else: pinA = 38 pinB = 36 GPIO.setup(pinA, GPIO.OUT) #On initialise les pins en sortie GPIO.setup(pinB, GPIO.OUT) self._pwm1 = GPIO.PWM(pinA, 1000) #On les mets en tant que sortie PWMs self._pwm2 = GPIO.PWM(pinB, 1000) #GPIO.setup(self._pinTacho1, GPIO.IN) #On initialise les entrée pour récupéré signal tacho #GPIO.setup(self._pinTacho2, GPIO.IN) return self
def setup(): global A global B global C global D global total_illumination_time GPIO.setmode(GPIO.BCM) # choose the correct GPIO pins depending on model revision = getrevision() #print "** revision: ", revision if ((revision == "0010") or (revision == "0012")): #print "Model B+ or A+" A, B, C, D = 21, 19, 26, 20 else: #print "Other model, probably Model A or Model B" A, B, C, D = 7, 9, 11, 8 if (bicolour_fitted): total_illumination_time = 6 * illumination_time_default total_illumination_time += illumination_time_bicolour_green total_illumination_time += illumination_time_bicolour_red else: total_illumination_time = 8 * illumination_time_default
def right_stop_at_black(): cap = cv2.VideoCapture(0) time.sleep(2) GPIO.setmode (GPIO.BCM) GPIO.setwarnings (False) GPIO.setup (23, GPIO.OUT) GPIO.setup (22, GPIO.OUT) PWML = GPIO.PWM (22,1) PWMR1 = GPIO.PWM (23,1) PWMR1.start(0) PWML.start(0) counter =0 while(1): ret, img = cap.read() PWMR1.ChangeDutyCycle(100) PWML.ChangeDutyCycle(100) ret,thresh = cv2.threshold(img,100,255,cv2.THRESH_BINARY) b1,g1,r1 = thresh[240,500] if b1==255: counter+=1 continue if counter>0: PWMR1.stop() PWML.stop() break GPIO.cleanup() cap.release() return
def switchWLAN(tmp): #kedipkan lampu WLAN for i in range(0, 29): GPIO.output(4, True) time.sleep(0.2) GPIO.output(4, False) time.sleep(0.2)
def lcd_toggle_enable(): # Toggle enable time.sleep(E_DELAY) GPIO.output(LCD_E, True) time.sleep(E_PULSE) GPIO.output(LCD_E, False) time.sleep(E_DELAY)
def Setup(self, authService): self.authService = authService io.setmode(io.BCM) self.lcd.begin(16, 2) self.LCDRefresh = True self.currentstate = "IDLE" self.lcd.backlight(0)
def init(): gpio.setmode(gpio.BOARD) gpio.setup(7, gpio.OUT) gpio.setup(11, gpio.OUT) gpio.setup(13, gpio.OUT) gpio.setup(15, gpio.OUT)
def forward(t): gpio.output(7, False) gpio.output(11, True) gpio.output(13, True) gpio.output(15, False) time.sleep(t) gpio.cleanup()
def main(): a=random.randint(1,10) preguntas() res=respuestas() while True: if(GPIO.input(7)): if(res==1): print "\nCorrecto! :)" if(res!=1): print "\nError :o" main() if(GPIO.input(8)): if(res==2): print "\nCorrecto! :)" if(res!=2) print "\nError :o" main() if(GPIO.input(9)): if(res==3): print "\nCorrecto! :)" if(res!=3) print "\nError :o" time.sleep(5) clear_output() main()
def set_up_gpio(self): # GPIO initialisation GPIO.setmode(GPIO.BOARD) GPIO.setup(self.SCK, GPIO.OUT, initial=GPIO.HIGH) GPIO.setup(self.CS, GPIO.OUT, initial=GPIO.HIGH) GPIO.setup(self.SDI, GPIO.OUT) GPIO.setup(self.SDO, GPIO.IN)
def __init__(self, lm1, lm2, rm1, rm2): self.status = "x" self.leftMotor = [lm1, lm2] self.rightMotor = [rm1, rm2] self.motors = self.leftMotor + self.rightMotor GPIO.setup(self.motors, GPIO.OUT) self.stop()
def on_message(client, userdata, msg): # log.info("incoming message (" + msg.topic + ")") if msg.topic == AWS_MQTT_SHADOW_TOPIC_PREFIX + userdata + \ "/shadow/update/delta": log.info("processing delta message") log.info("payload:{0}\n userdata:{1}".format(msg.payload.decode(), userdata)) j = json.loads(msg.payload.decode()) if "lock" in j["state"].keys(): log.info("set LED state to: {0}".format(j["state"]["lock"])) GPIO.output(LOCK_PIN, j["state"]["lock"]) if "alarm_reset" in j["state"].keys(): if j["state"]["alarm_reset"] == 1 and reset_queue.qsize() == 0: log.debug("reset alarm") global alarm_reset alarm_reset = 1 reset_queue.put(False) else: global alarm_reset alarm_reset = 0 elif msg.topic == AWS_MQTT_SHADOW_TOPIC_PREFIX + userdata + \ "/shadow/update/accepted": # log.info("message state accepted") pass elif msg.topic == AWS_MQTT_SHADOW_TOPIC_PREFIX + userdata + \ "/shadow/update/rejected": log.error("message state rejected. Reason: {0}" .format(str(msg.payload)))
def main(): # tell the GPIO module that we want to use the # chip's pin numbering scheme GPIO.setmode(GPIO.BCM) # setup pin 25 as an output GPIO.setup(17,GPIO.IN) GPIO.setup(18,GPIO.IN) while True: if GPIO.input(17): print "Vision Api activated" try: rc = subprocess.call("cd /home/pi/unblind && sh /home/pi/unblind/visionapi.sh && cd -", shell=True) except OSError as e: print( e ) print "button17 true" if GPIO.input(18): print "OCR Api activated" try: rc = subprocess.call("cd /home/pi/unblind && sh /home/pi/unblind/ocr.sh && cd -", shell=True) except OSError as e: print( e ) print "button18 true" time.sleep(0.1) GPIO.cleanup()
def safety_callback(channel): try: code="" type="" if(GPIO.input(2) == GPIO.LOW): #todo type="emergency" serial.flushInput() serial.write("M730\r\n") reply=serial.readline() try: code=float(reply.split("ERROR : ")[1].rstrip()) except: code=100 if(GPIO.input(2) == GPIO.HIGH): #to do type="" code="" message = {'type': str(type), 'code': str(code)} ws.send(json.dumps(message)) write_emergency(json.dumps(message)) except Exception, e: logging.info(str(e))
def reverse(t): gpio.output(7, True) gpio.output(11, False) gpio.output(13, False) gpio.output(15, True) time.sleep(t) gpio.cleanup()
def __init__(self): threading.Thread.__init__(self) #threading-class initialisieren self.daemon = True self.port = rc.config.get('monitor','arduino_port') self.sensor_threshold_min = rc.config.getint('monitor','sensor_threshold_min') self.pir = rc.config.getboolean('monitor','pir') if(self.pir): import RPi.GPIO as GPIO self.pirGPIO = rc.config.getint('monitor','pirGPIO') GPIO.setmode(GPIO.BOARD) GPIO.setup(self.pirGPIO,GPIO.IN) self.pirFunc = rc.config.getint('monitor','pirFunc') #pir works as sensor or filter if (self.pirFunc == 2): self.pirStarttime = 0 #try: # import pigpio #except ImportError: # self.pigpio = None #else: # self.pigpio = pigpio # self.pirGPIO = rc.config.getint('monitor','pirGPIO') # self.pirFunc = rc.config.getint('monitor','pirFunc') # self.pigpio.start() # self.pigpio.set_mode(self.pirGPIO, self.pigpio.INPUT) # if (self.pirFunc == 2): # self.pirStarttime = 0 self.starttime = 0 #read absence self.absence = absence.Absence()
def rightTurn(t): gpio.output(7, False) gpio.output(11,True) gpio.output(13, False) gpio.output(15, True) time.sleep(t) gpio.cleanup()
def cleanup (self): self.__off() if Heating.__instances == 1: io.cleanup() else: with Heating.__instances_lock: Heating.__instances -= 1
def leftTurn(t): gpio.output(7,True) gpio.output(11,False) gpio.output(13,True) gpio.output(15,False) time.sleep(t) gpio.cleanup()
def changesong(channel2): global songthis songthis=songthis+1 if songthis>7: songthis=0 GPIO.output(lightList[0:8],0) GPIO.output(lightList[songthis],1)
def set(pin, status): GPIO.setup(pin, GPIO.OUT) if status == True: status=GPIO.LOW else: status=GPIO.HIGH GPIO.output(pin, status)
def main(): salir=1 #init. startLog() GPIO.setmode(GPIO.BCM) rele=ClassRele() led=ClassLed() DHT_Temp = temperature.ClassTemp() horarios = TiemposCalendar.classHorrarios() ReportTemp = report.calssReport() sys.stderr.write('%s Started bucle.\n' ) while (salir): #loop. ValueTemp = DHT_Temp.SucesoTemp() ahora = horarios.suceso() if (ValueTemp[1] < ahora): encendido = 1 else: encendido = 0 led.suceso(encendido) rele.suceso(encendido) ReportTemp.suceso([ValueTemp[1], ValueTemp[2],ahora,encendido ]) sleep(0.3)
def __init__(self, channel, led_pin, f): self.channel = channel self.f = f self.led_pin = led_pin self.p = Process(target=self.target_f) GPIO.setup(self.channel, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(self.led_pin, GPIO.OUT, initial=GPIO.LOW)
def cleanup(): #Stop all the PWM objects RED.stop() GREEN.stop() BLUE.stop() #Tidy up and remaining connections. GPIO.cleanup()
def __init__(self): GPIO.setmode(GPIO.BCM) GPIO.setup(4,GPIO.IN,pull_up_down = GPIO.PUD_DOWN) ''' Constructor ''' #config=dict() #with open('apiconfigs.txt', 'rb') as fp: #config = json.load(fp) #self.twitter=Twitter(config["twitter"]) #self.facebook=Facebook(config["facebook"]) #self.printer=Printer() #self.uploader=UploadServer() self.cameraToRasterQueue = Queue.Queue() self.rasterToPrinterQueue = Queue.Queue() self.cameraToSocialPreprocessorQueue = Queue.Queue() self.quitEvent = threading.Event() print "made events and queues" print "init imageprocessor and social preprocessor" self.imageProcessor=ImageProcessor( self.quitEvent, self.cameraToRasterQueue, self.rasterToPrinterQueue, self.cameraToSocialPreprocessorQueue) print "init picamera" #GPIO.setup(18,GPIO.OUT) #pwmLed=GPIO.PWM(18,2000) ledDriver=LedDriver() self.picamera=Picamera( self.quitEvent, self.cameraToRasterQueue,self.cameraToSocialPreprocessorQueue,ledDriver) print "init printer" self.printer=SimpleThermalPrinter( self.quitEvent, self.rasterToPrinterQueue) '''state thread'''
def cleanup(): GPIO.cleanup() print "GPIO CLEANED" hotconn.close() histconn.close() print "DATABASE CONNECTION CLOSED" print "PROGRAM TERMINATED SUCCESSFULLY"
def on(self): ''' Set the led on ''' if not self.__is_pulse: GPIO.output(self.__pin, self.__real_true) self.__is_on = True
def mainFunction(): """ This is the mainfunction. Here we chose wich other function we want to run using a keypad that is connected to the raspberry pi. """ global keypad print("Voer een getal in door middel van de keypad.") try: functions = [login, adUser, treadmill, device2, device3, device4, device5]#create a list of functions while True: if keypad.getKey() and 0 < int(keypad.getKey()) < 7: print("key pressed") keypadCharacter = int(keypad.getKey())#store the pressed key in the keypadCharacter variable keypadCharacter-=1 functions[keypadCharacter]() elif keypad.getKey() and not 0 < int(keypad.getKey()) < 7: print("Het getal dat u ingevoerd heeft is te hoog of te laag") #needed to be split in to high or low? sleep(2) sleep(0.1) # except ValueError: # print("Dit is geen getal voer altublieft een getal in.") # mainFunction() # except: # sleep(1) # sys.exit() finally: print("exiting") GPIO.cleanup()
def set_value(value): for i in range(8): bitwise=0x80>>i val = gpio.HIGH if bitwise&value else gpio.LOW gpio.output(ds, val) tick(clock) tick(latch)