def __init__(self, trig, echo): self.TRIG = trig self.ECHO = echo gpio.setFunction(self.TRIG, 'DIGITAL') gpio.setFunction(self.ECHO, 'DIGITAL') gpio.setMode(self.TRIG, 'output') gpio.setMode(self.ECHO, 'input') print('GPIO set is OK: Trig os: ', self.TRIG, ' Echo is:', self.ECHO) time.sleep(0.3)
def __init__(self, broker, PIN, POLLING): self._broker = broker self._PIN = PIN self._POLLING = POLLING # setup matrix voice pins gpio.setFunction(self._PIN, 'DIGITAL') gpio.setMode(self._PIN, 'input') # thread for polling to press events on the button self._thread_button_flag = threading.Event() self._thread_button = threading.Thread( target=self._check_pressed, name='voice-app-alarm-switch-button', daemon=True) self._thread_button.start()
def __init__(self, broker, PIN, POLLING): self._broker = broker self._broker.subscribe('alarm-info', self._alarm_info_received) self._broker.subscribe('trigger-button-alarm-info', self._triggered_button_alarm_info) self.alarm_info_received = False self._PIN = PIN self._POLLING = POLLING # setup matrix voice pins gpio.setFunction(self._PIN, 'DIGITAL') gpio.setMode(self._PIN, 'input') # thread for polling to press events on the button self._thread_button_flag = threading.Event() self._thread_button = threading.Thread( target=self._check_pressed, name='alarm-info-button', daemon=True) self._thread_button.start()
def setup(self): gpio.setFunction(self._buzzer_pin, 'DIGITAL') gpio.setMode(self._buzzer_pin, 'output')
import serial import time ser = serial.Serial() ser.port='/dev/ttyUSB2' ser.baudrate=115200 ser.open() ser.write("\r\n\r\n".encode()) # Hit enter a few times to wake the printer time.sleep(2) # Wait for printer to initialize ser.flushInput() ##3D Printer relayPin = 0 gpio.setFunction(relayPin, 'DIGITAL') gpio.setMode(relayPin, "output") gpio.setDigital(relayPin,1) MQTT_IP_ADDR = "localhost" MQTT_PORT = 1883 MQTT_ADDR = "{}:{}".format(MQTT_IP_ADDR, str(MQTT_PORT)) availableDevice = ['printer'] class snips_power_app(object): def __init__(self): # get the configuration if needed try: self.config = SnipsConfigParser.read_configuration_file(CONFIG_INI)
def motorInit(): gpio.setMode(8, 'output') gpio.setFunction(8, 'pwm') gpio.setMode(14, 'output') gpio.setFunction(14, 'pwm') gpio.setFunction(12, 'DIGITAL') gpio.setFunction(10, 'DIGITAL') gpio.setFunction(6, 'DIGITAL') gpio.setFunction(4, 'DIGITAL') gpio.setMode(10, 'output') gpio.setMode(12, 'output') gpio.setMode(6, 'output') gpio.setMode(4, 'output')
terminate[n] = 1 led.set((color[0],color[1],color[2],color[3])) print(color) time.sleep(delay) return array_gen(color) def fade_out(max_color): led.set('black') min_color = [0,0,0,0] terminate = [0,0,0,0] terminate = [0,0,0,0] while terminate != [1,1,1,1]: for n in range(4): if color[n] > min_color[n]: color[n] -= (max_color[n]/255) else: terminate[n] = 1 led.set((color[0],color[1],color[2],color[3])) print(color) time.sleep(.002) gpio.setFunction(0, 'DIGITAL') gpio.setMode(0, "input") while True: led.set('Black') temperatureReadout(0) humidityReadout() heatIndex() led.set('Black')