def makeGrogg2(): GPIO.output(soda_2, False) GPIO.output(liquor_2, False) sprit = Timer(1.9, turnOffBooze2) virke = Timer(8.5, turnOffSoda2) sprit.start() virke.start()
def api_leds_control(color): if request.method == "POST": if color in LEDS: #GPIO.output(18,True) GPIO.output(LEDS[color], int(request.data.get("state"))) return {color: GPIO.getStatePinOut(LEDS[color])}
def makeGrogg4(): GPIO.output(liquor_4, False) sprit = Timer(1.9, turnOffBooze4) sprit.start() virke.start()
def makeGrogg1(): GPIO.output(soda_1, False) GPIO.output(liquor_1, False) sprit = Timer(1.9, turnOffBooze1) virke = Timer(8.5, turnOffSoda1) sprit.start() virke.start()
def control(pin, action): if pin == 'fourteen': actuator = 14 if pin == 'fifteen': actuator = 15 if pin == 'eighteen': actuator = 18 if pin == 'twentythree': actuator = 23 if pin == 'twentyfour': actuator = 24 if pin == 'twentyfive': actuator = 25 if pin == 'eight': actuator = 8 if pin == 'seven': actuator = 7 if pin == 'twelve': actuator = 12 if pin == 'sixteen': actuator = 16 if pin == 'twenty': actuator = 20 if pin == 'twentyone': actuator = 21 if pin == 'two': actuator = 2 if pin == 'three': actuator = 3 if pin == 'four': actuator = 4 if pin == 'seventeen': actuator = 17 if pin == 'twentyseven': actuator = 27 if pin == 'twentytwo': actuator = 22 if pin == 'ten': actuator = 10 if pin == 'nine': actuator = 9 if pin == 'eleven': actuator = 11 if pin == 'five': actuator = 5 if pin == 'six': actuator = 6 if pin == 'thirteen': actuator = 13 if pin == 'nineteen': actuator = 19 if pin == 'twentysix': actuator = 26 if action == 'on': GPIO.output(actuator, GPIO.HIGH) if action == 'off': GPIO.output(actuator, GPIO.LOW)
def stop(self): self.mirror.stop() self.led_strip.stop() self.sound.stop(100) # Let the thread finish if self.mirror.thr is not None: while self.mirror.thr.isAlive(): Logger.write.info("waiting for thread to finish") pass GPIO.output(RELAYS[1], RELAY_OFF)
def state_changed(self, state): Logger.write.info("pin status: " + str(state)) if state == True: if not self.sound.is_busy(): self.sound.play() else: Logger.write.info("Sound already playing") # time.sleep(1.5) # GPIO.output(RELAYS[1], RELAY_ON) # relay 1 # time.sleep(2) self.led_strip.run() self.mirror.run() else: self.mirror.stop() self.led_strip.stop() time.sleep(1.5) self.sound.stop() GPIO.output(RELAYS[1], RELAY_OFF)
def init_gpio(relay_list, quiet=True): Logger.write.info("Initializing relays, please wait") GPIO.setmode(GPIO.BCM) GPIO.setup(SENSOR_GPIO_PIN, GPIO.IN, pull_up_down=SENSOR_PUD) for pin in relay_list: GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, RELAY_OFF) if not quiet: for pin in relay_list: # cycle individual GPIO.output(pin, RELAY_ON) time.sleep(0.25) GPIO.output(pin, RELAY_OFF) time.sleep(0) for pin in relay_list: # all on GPIO.output(pin, RELAY_ON) time.sleep(1.0) for pin in relay_list: # all off GPIO.output(pin, RELAY_OFF)
def turnOffSoda2(): GPIO.output(soda_2, True)
def mfr(): GPIO.output(b, True) GPIO.output(d, False)
def lightoff(LEDS, i): GPIO.output(LEDS[i], GPIO.LOW)
def handle_door(req): rospy.loginfo('sending open door command to door %s', req.door_id) if req.door_id == 1: GPIO.output(2, GPIO.HIGH) time.sleep(1) GPIO.output(2, GPIO.LOW) elif req.door_id == 2: GPIO.output(3, GPIO.HIGH) time.sleep(1) GPIO.output(3, GPIO.LOW) elif req.door_id == 3: GPIO.output(4, GPIO.HIGH) time.sleep(1) GPIO.output(4, GPIO.LOW) return True
##import RPi.GPIO as GPIO from EmulatorGUI import GPIO import time #asigno el nodo al puerto GPIO GPIO.setmode(GPIO.BCM) # Configuro si el pin es entrada o salida GPIO.setup(7, GPIO.OUT) while True: # envio la señal por ese puerto GPIO.output(7, True) time.sleep(1) GPIO.output(7, False) time.sleep(1)
def Main(): try: GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Kasa Açıldı GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Ev Kapısı Açıldı GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Araba Açık GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Araba Kapısı Kapandı GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Ev Kapısı Kapandı GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Kasa Kapandı GPIO.setup(4, GPIO.OUT, initial=GPIO.HIGH) # Kasa Açık 1, Kasa Kapalı 0 GPIO.setup(9, GPIO.OUT, initial=GPIO.LOW) # Ev Açık 1, Ev Kapalı 0 GPIO.setup(17, GPIO.OUT, initial=GPIO.HIGH) # Araba Açık 1, Araba Kapalı 0 GPIO.setup(19, GPIO.OUT, initial=GPIO.LOW) # Nem kontrol GPIO.output(4, GPIO.LOW) GPIO.output(9, GPIO.LOW) GPIO.output(17, GPIO.LOW) Kasakapaliguncelle() Evkapaliguncelle() Arabakapaliguncelle() while (True): if (GPIO.input(14) == True): GPIO.output(4, GPIO.HIGH) Kasaacikguncelle() if (GPIO.input(8) == True): GPIO.output(4, GPIO.LOW) Kasakapaliguncelle() if (GPIO.input(15) == True): GPIO.output(9, GPIO.HIGH) Evacikguncelle() if (GPIO.input(16) == True): GPIO.output(9, GPIO.LOW) Evkapaliguncelle() if (GPIO.input(18) == True): GPIO.output(17, GPIO.HIGH) Arabaacikguncelle() if (GPIO.input(25) == True): GPIO.output(17, GPIO.LOW) Arabakapaliguncelle() con.close() except Exception as ex: traceback.print_exc() finally: GPIO.cleanup()
def stop(): GPIO.output(a, False) GPIO.output(b, False) GPIO.output(c, False) GPIO.output(d, False)
def mbr(): GPIO.output(d, True) GPIO.output(b, False)
def mbl(): GPIO.output(c, True) GPIO.output(a, False)
def makeGrogg3(): GPIO.output(liquor_3, False) sprit = Timer(1.9, turnOffBooze3) sprit.start()
def turnOffBooze3(): GPIO.output(liquor_3, True)
def turnOffBooze4(): GPIO.output(liquor_4, True)
def _thread_func(self): current_time_ratio = 0.0 # How far into the timeslots we currently are, from 0 to 1 time_ratio_advance = 1.0 / self.PWM_TIMESLOTS while time.sleep(self.SLEEP_DELAY): # Set LEDs to appropriate values for seg in range(LED_NUM_SEGS): for color in LED_COLORS: # IMPORTANT: Implicitly dictates pin order for LEDs after shift register below if self.state[seg][color] > current_time_ratio: # Push a high on the shift register GPIO.output(DATA_PIN, GPIO.high) time.sleep(self.TRIGGER_DELAY) GPIO.output(LATCH_PIN, GPIO.high) time.sleep(self.TRIGGER_DELAY) GPIO.output(LATCH_PIN, GPIO.low) time.sleep(self.TRIGGER_DELAY) GPIO.output(DATA_PIN, GPIO.low) else: # Push a low on the shift register GPIO.output(DATA_PIN, GPIO.low) time.sleep(self.TRIGGER_DELAY) GPIO.output(LATCH_PIN, GPIO.high) time.sleep(self.TRIGGER_DELAY) GPIO.output(LATCH_PIN, GPIO.low) time.sleep(self.TRIGGER_DELAY) GPIO.output(DATA_PIN, GPIO.low) # Push updated states out to LED strip time.sleep(self.TRIGGER_DELAY) GPIO.output(PUSH_OUT_PIN, GPIO.high) time.sleep(self.TRIGGER_DELAY) GPIO.output(PUSH_OUT_PIN, GPIO.low) # Increment segment, resetting upon reaching 1 to 0 current_time_ratio += time_ratio_advance if current_time_ratio == 1.0: current_time_ratio = 0.0
def turnOffBooze1(): GPIO.output(liquor_1, True)
def control(pin, action): contract_instance = w3.eth.contract(abi=abi, address=contract_address, ContractFactoryClass=ConciseContract) if pin == 'fourteen': actuator = 14 if pin == 'fifteen': actuator = 15 if pin == 'eighteen': actuator = 18 if pin == 'twentythree': actuator = 23 if pin == 'twentyfour': actuator = 24 if pin == 'twentyfive': actuator = 25 if pin == 'eight': actuator = 8 if pin == 'seven': actuator = 7 if pin == 'twelve': actuator = 12 if pin == 'sixteen': actuator = 16 if pin == 'twenty': actuator = 20 if pin == 'twentyone': actuator = 21 if pin == 'two': actuator = 2 if pin == 'three': actuator = 3 if pin == 'four': actuator = 4 if pin == 'seventeen': actuator = 17 if pin == 'twentyseven': actuator = 27 if pin == 'twentytwo': actuator = 22 if pin == 'ten': actuator = 10 if pin == 'nine': actuator = 9 if pin == 'eleven': actuator = 11 if pin == 'five': actuator = 5 if pin == 'six': actuator = 6 if pin == 'thirteen': actuator = 13 if pin == 'nineteen': actuator = 19 if pin == 'twentysix': actuator = 26 if action == 'on': config = 1 if action == 'off': config = 0 contract_instance.control(actuator, config, transact={'from': w3.eth.accounts[0]}) print("Transaction its Way..") y = format(contract_instance.pinStatus(actuator)) print(y) if y == "1": GPIO.output(actuator, GPIO.HIGH) else: GPIO.output(actuator, GPIO.LOW) templateData = {'title': "GPIO Control"} return render_template('index.html', **templateData)
def turnOffSoda1(): GPIO.output(soda_1, True)
def main(): GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) GPIO.setup(18, GPIO.OUT) GPIO.setup(22, GPIO.OUT) GPIO.setup(23, GPIO.OUT) print('Red LED on') GPIO.output(17, True) time.sleep(3) GPIO.output(17, False) time.sleep(1) print('Yellow LED on') GPIO.output(18, True) time.sleep(3) GPIO.output(18, False) time.sleep(1) print('Green LED on') GPIO.output(22, True) time.sleep(3) GPIO.output(22, False) time.sleep(1) print('Blue LED on') GPIO.output(23, True) time.sleep(3) GPIO.output(23, False)
##import RPi.GPIO as GPIO from EmulatorGUI import GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(14, GPIO.OUT) GPIO.setup(15, GPIO.IN) while True: if GPIO.input(14): GPIO.output(15, False) else: GPIO.output(15, True)
def lighton(LEDS, i): GPIO.output(LEDS[i], GPIO.HIGH)
def turnOffBooze2(): GPIO.output(liquor_2, True)
def Main(): try: GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(4, GPIO.OUT) GPIO.setup(17, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(18, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(21, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(26, GPIO.IN) while (True): if (GPIO.input(23) == False): GPIO.output(4, GPIO.HIGH) GPIO.output(17, GPIO.HIGH) time.sleep(1) if (GPIO.input(15) == True): GPIO.output(18, GPIO.HIGH) GPIO.output(21, GPIO.HIGH) time.sleep(1) if (GPIO.input(24) == True): GPIO.output(18, GPIO.LOW) GPIO.output(21, GPIO.LOW) time.sleep(1) if (GPIO.input(26) == True): GPIO.output(4, GPIO.LOW) GPIO.output(17, GPIO.LOW) time.sleep(1) except Exception as ex: traceback.print_exc() finally: GPIO.cleanup() #this ensures a clean exit
def mfl(): GPIO.output(a, True) GPIO.output(c, True)