def exit(self): """ Cleans-up and releases all resources. """ global _isButtonEnabled Tools.debug("Calling Robot.exit()") self.setButtonEnabled(False) # Stop motors SharedConstants.LEFT_MOTOR_PWM[0].ChangeDutyCycle(0) SharedConstants.LEFT_MOTOR_PWM[1].ChangeDutyCycle(0) SharedConstants.RIGHT_MOTOR_PWM[0].ChangeDutyCycle(0) SharedConstants.RIGHT_MOTOR_PWM[1].ChangeDutyCycle(0) # Stop button thread, if necessary if _buttonThread != None: _buttonThread.stop() # Stop display display = Display._myInstance if display != None: display.stopTicker() display.clear() Led.clearAll() MyRobot.closeSound() if self.sensorThread != None: self.sensorThread.stop() self.sensorThread.join(2000) # GPIO.cleanup() Do not cleanup, otherwise button will not work any more when coming back # from remote execution Tools.delay(2000) # avoid "sys.excepthook is missing"
def __init__(self, db): # Call the parent class (Sprite) constructor super().__init__() alarm_ref = db.collection(u'Users').document( 'y2wiAwN8e1e52SWtvVD3BNFiWGu2').collection('People').document( 'Indy').collection('Sensors').document('alarmCheck') try: alarm = alarm_ref.get() val = format(alarm.to_dict()['alarm']) print(val) if val == 'True': print('alarm on') Led(0) print('alarm off') Led(1) print('alarm off') Buzz(1) Heartbeat(db, 100, 113) # hier de hogere waarden else: Led(1) Buzz(0) print('he') Heartbeat(db, 61, 99) # hier de lagere waarden time.sleep(1) except google.cloud.exceptions.NotFound: print( u'No AlarmCheck document was found, check your firestore database!' )
def exit(self): """ Cleans-up and releases all resources. """ global _isButtonEnabled Tools.debug("Calling Robot.exit()") self.setButtonEnabled(False) # Stop motors SharedConstants.LEFT_MOTOR_PWM[0].ChangeDutyCycle(0) SharedConstants.LEFT_MOTOR_PWM[1].ChangeDutyCycle(0) SharedConstants.RIGHT_MOTOR_PWM[0].ChangeDutyCycle(0) SharedConstants.RIGHT_MOTOR_PWM[1].ChangeDutyCycle(0) # Stop button thread, if necessary if _buttonThread != None: _buttonThread.stop() # Stop display display = Display._myInstance if display != None: display.stopTicker() display.clear() Led.clearAll() Tools.delay(2000) # avoid "sys.excepthook is missing"
def setup(self): self.settings = SettingsSingleton.getInstance() self.rSettings = self.settings.getRelaySettings(self.name) if not self.rSettings: print('Relay settings are incorrect!') sys.exit(1) try: self.pinNr = self.rSettings["relay_pin"] except: print('Relay pin number is missing!') sys.exit(1) if not (self.pinNr >= 0): print('Relay pin number is incorrect!') sys.exit(1) invertState = "false" try: invertState = self.rSettings["invert"] if not (invertState == "false"): self.off = 1 self.on = 0 except: pass try: self.min_time_change = self.settings.get('button_pressed_time') except: pass self.pin = machine.Pin(self.pinNr, machine.Pin.OUT) self.pin.value(self.off) try: button_pin = self.rSettings["button_pin"] self.button = Button(button_pin) self.button.setup() except: # no button for this relay pass led_default_state = 0 try: led_default_state = self.rSettings["default_led_state"] except: pass try: led_pin = self.rSettings["led_pin"] self.led = Led(led_pin, led_default_state) self.led.setup() except: # no led for this relay pass
async def tryToTakePhoto(self): camera = Camera() if (await camera.takePhoto() == 0): return 0 else: alarme = Alarme() led = Led() alarme.start() led.start() return 1
def __init__(self, pin_led, pin_sw, debug=False): print('pin_led:%d' % pin_led) print('pin_sw :%d' % pin_sw) self.pin_led = pin_led self.pin_sw = pin_sw self.long_press = [ { 'timeout': 0.7, 'blink': { 'on': 1, 'off': 0 } }, # multi click { 'timeout': 1, 'blink': { 'on': 0.2, 'off': 0.04 } }, # blink1 { 'timeout': 3, 'blink': { 'on': 0.1, 'off': 0.04 } }, # blink2 { 'timeout': 5, 'blink': { 'on': 0.02, 'off': 0.04 } }, # blink3 { 'timeout': 7, 'blink': { 'on': 0, 'off': 0 } } ] # end self.timeout_sec = [] for i in range(len(self.long_press)): self.timeout_sec.append(self.long_press[i]['timeout']) self.sw = Switch(self.pin_sw, self.timeout_sec, debug=debug) self.sl = SwitchListener([self.sw], self.sw_callback, debug=debug) self.led = Led(self.pin_led) self.active = True
def pararTodos(posturaCrouch=True): try: Led.corpoRGB() bm = Comportamento.conn() bm.stopAllBehaviors() if posturaCrouch: Motor.posturaCrouch() return True except Exception as e: print("Exception -> Comportamento.pararTodos():", e) return False
def __init__(self, config): self.__config = config self.__navegador = Navegador(self.__config) self.__sensorDeObjetos = SensorDeObjetos( config.DomoPatronAReconocer, config.DomoCamaraId, config.DomoMostrarEnVentanaReconocimiento, config.DomoFotogramasXCaptura) self.__testigoLuminoso = Led() self.__testigoSonoro = Buzzer() if self.__config.DomoMostrarEnVentanaCentrado: cv.NamedWindow(self.__windowName, 1) self.__debugMode = self.__config.DomoDebugMode
def start(self): self.addSegment(Segment(self, 9, 120, "mid")) self.addSegment(Segment(self, 120, 240, "end")) thread.start_new_thread(self.listenToInput, ()) thread.start_new_thread(self.serverSetup, ()) for x in range(0, 240): self.pixels.append(Led(self, x)) self.strip = Adafruit_NeoPixel(240, 18, 800000, 11, False, 255) self.strip.begin() self.strip.show() self.loadSceiptsNew("") #self.loadScripts("./scripts") self.loadPackets("./packets") self.segments[0].setScript(self.scripts[8]) self.strip.setPixelColorRGB(120, 250, 0, 0) self.strip.show() print self.scripts print len(self.scripts) #print("starting..") while self.running: try: self.sleep(1) except KeyboardInterrupt: self.running = False print("Stop running") except: print("Error Caught") raise
def __init__ (self, config): self.__config = config self.__navegador = Navegador(self.__config) self.__sensorDeObjetos = SensorDeObjetos(config.DomoPatronAReconocer, config.DomoCamaraId, config.DomoMostrarEnVentanaReconocimiento, config.DomoFotogramasXCaptura) self.__testigoLuminoso = Led() self.__testigoSonoro = Buzzer() if self.__config.DomoMostrarEnVentanaCentrado : cv.NamedWindow(self.__windowName,1) self.__debugMode = self.__config.DomoDebugMode
def __init__(self, motor=None, headlight=None, taillight=None, buzzer=None, display=None): self.PWM = motor self.serverup = False self.automode = False self.taillight = taillight self.TCP_Server = Server(motor, headlight, taillight, buzzer) self.adc = Adc() self.led = Led() self.buzzer = buzzer self.myservo = Servo() self.display = display print "Initializing..." self.on_pushButton()
def __init__(self, size): self.size = size self.ledList = [] self.cycle = 0 self.ball = Ball(size - 1) self.humanPlayer = HumanPlayer(size / 2, size - 1) for i in range(0, size * size): self.ledList.append(Led())
def __init__(self, pin_led, pin_sw, debug=False): self.pin_led = pin_led self.pin_sw = pin_sw self.long_press = [ {'timeout':0.7, 'blink':{'on':1, 'off':0}}, {'timeout':1, 'blink':{'on':0.2, 'off':0.04}}, {'timeout':3, 'blink':{'on':0.1, 'off':0.04}}, {'timeout':5, 'blink':{'on':0.04, 'off':0.04}}, {'timeout':7, 'blink':{'on':0, 'off':0}}] self.timeout_sec = [] for i in range(len(self.long_press)): self.timeout_sec.append(self.long_press[i]['timeout']) self.sw = SwitchListener([self.pin_sw], self.sw_callback, timeout_sec=self.timeout_sec, debug=debug) self.led = Led(self.pin_led) self.active = True
def exit(self): """ Cleans-up and releases all resources. """ global _isButtonEnabled Tools.debug("Calling Robot.exit()") self.setButtonEnabled(False) # Stop motors SharedConstants.LEFT_MOTOR_PWM[0].ChangeDutyCycle(0) SharedConstants.LEFT_MOTOR_PWM[1].ChangeDutyCycle(0) SharedConstants.RIGHT_MOTOR_PWM[0].ChangeDutyCycle(0) SharedConstants.RIGHT_MOTOR_PWM[1].ChangeDutyCycle(0) # Stop button thread, if necessary if _buttonThread != None: _buttonThread.stop() # Stop display display = Display._myInstance if display != None: display.stopTicker() display.clear() if self.isPCA9685Available: Led.clearAll() MyRobot.closeSound() if self.sensorThread != None: self.sensorThread.stop() self.sensorThread.join(2000) # GPIO.cleanup() # Do not cleanup, otherwise button will not work any more when coming back from remote execution Tools.delay(2000) # avoid "sys.excepthook is missing"
class Domo: __navegador = None __sensorDeObjetos = None __testigoLuminoso = None __testigoSonoro = None __config = None __windowName = "Visor de Centrado" __domoMostrarMovimiento = False """ Ventana Eje (min,max) """ __ventanaX = None __ventanY = None """ Constructor """ def __init__ (self, config): self.__config = config self.__navegador = Navegador(self.__config) self.__sensorDeObjetos = SensorDeObjetos(config.DomoPatronAReconocer, config.DomoCamaraId, config.DomoMostrarEnVentanaReconocimiento, config.DomoFotogramasXCaptura) self.__testigoLuminoso = Led() self.__testigoSonoro = Buzzer() if self.__config.DomoMostrarEnVentanaCentrado : cv.NamedWindow(self.__windowName,1) self.__debugMode = self.__config.DomoDebugMode """ Destructor """ def __del__(self): if self.__config.DomoMostrarEnVentanaCentrado : cv.DestroyWindow(self.__windowName) """ Calcula las coordenadas de las ventanas una unica vez de acuerdo al tamano de la imagen """ def __calcularVentana(self): if self.__ventanaX == None and self.__ventanY == None : imgSize = self.__sensorDeObjetos.getImageSize() imgSizeX = imgSize[0] imgSizeY = imgSize[1] tmpPrincipio = int((imgSizeX - self.__config.DomoVentanaHorizontal)/2) tmpFin = imgSizeX - tmpPrincipio self.__ventanaX = (tmpPrincipio,tmpFin) tmpPrincipio = int((imgSizeY - self.__config.DomoVentanaVertical)/2) tmpFin = imgSizeY - tmpPrincipio self.__ventanaY = (tmpPrincipio,tmpFin) """ Posiciona el Domo """ def posicionar(self): self.__sensorDeObjetos.capturar() self.__calcularVentana() if self.__sensorDeObjetos.haveObjects() : self.__testigoLuminoso.encender() if self.__config.DomoMover : self.__posicionar() else : self.__testigoLuminoso.apagar() """ Calcula la posicion """ def __posicionar(self): coordenadas = self.__sensorDeObjetos.getObjectPosition() """ ((x, y, w, h), n) """ x = coordenadas[0] y = coordenadas[1] w = coordenadas[2] h = coordenadas[3] n = coordenadas[4] cx = int(x + (w /2)) cy = int(y + (h /2)) mov = self.__calcularMovimientoDomo(x, y, w, h, n, cx, cy) movX = mov[0] movY = mov[1] movZ = mov[2] if self.__config.DomoMostrarEnVentanaCentrado : self.__mostrarCentradoEnVentana(cx,cy, movX, movY) self.__realizarMovimientos(movX, movY, movZ) """ Muestra una imagen con la 'Ventana' para la imagen """ def __mostrarCentradoEnVentana(self,cx,cy,movX,movY): tmpImage = self.__sensorDeObjetos.getImage() cv.Circle(tmpImage, (cx,cy), 3, cv.RGB(255, 0, 0)) cv.Line(tmpImage, (self.__ventanaX[0],0), (self.__ventanaX[0],tmpImage.height), cv.RGB(255, 0, 0)) cv.Line(tmpImage, (self.__ventanaX[1],0), (self.__ventanaX[1],tmpImage.height), cv.RGB(255, 0, 0)) cv.Line(tmpImage, (0,self.__ventanaY[0]), (tmpImage.width,self.__ventanaY[0]), cv.RGB(255, 0, 0)) cv.Line(tmpImage, (0,self.__ventanaY[1]), (tmpImage.width,self.__ventanaY[1]), cv.RGB(255, 0, 0)) imgCenterX = int(tmpImage.width/2) imgCenterY = int(tmpImage.height/2) cv.Circle(tmpImage, (imgCenterX,imgCenterY), 3, cv.RGB(0, 0, 255)) if self.__debugMode : print movX,movY cv.Line(tmpImage, (imgCenterX,imgCenterY), (imgCenterX+ (movX*self.__config.DomoPixelesPorMovimientoDebugLineX),imgCenterY), cv.RGB(0, 0, 255)) cv.Line(tmpImage, (imgCenterX,imgCenterY), (imgCenterX,imgCenterY+ (movY*self.__config.DomoPixelesPorMovimientoDebugLineX)), cv.RGB(0, 0, 255)) """cv.SaveImage("ImagenCentrado.jpg", tmpImage)""" cv.ShowImage(self.__windowName, tmpImage) return cv.WaitKey(10) <= 0 """ Calcula el moviemiento del domo """ def __calcularMovimientoDomo(self, x, y, w, h, n, cx, cy): return ( self.__calcularCantidadMoviemientoEje(self.__ventanaX, cx), self.__calcularCantidadMoviemientoEje(self.__ventanaY, cy), self.__calcularCantidadMoviemientoDistancia(w)) """ Realiza el moviemiento del domo """ def __realizarMovimientos(self,movX,movY, movZ): self.__navegador.mover(movX,movY,movZ) """ Devuelve la cantidad de movimientos que hay que realizar para centrar el Objeto """ def __calcularCantidadMoviemientoEje(self, ventana, centroFigura): centroFronteraPrincipio = ventana[0]; centroFronteraFin = ventana[1]; if centroFigura < centroFronteraPrincipio : return self.__pixelesAMovimiento(centroFigura - centroFronteraPrincipio) elif centroFigura > centroFronteraFin : return self.__pixelesAMovimiento(centroFigura - centroFronteraFin) else : return 0 """ Devuelve la cantidad de movimientos que hay que realizar para centrar el Objeto en Z """ def __calcularCantidadMoviemientoDistancia(self,width): minimo = self.__config.DomoVentanaDistanciaMinima maximo = self.__config.DomoVentanaDistanciaMaxima if width < minimo : return minimo - width elif width > maximo : return maximo - width else : return 0 """ Devuelve la cantidad de movimientos que implica la cantidad de pixeles pasada """ def __pixelesAMovimiento(self,pixeles): return int(round(pixeles / self.__config.DomoPixelesPorMovimiento))
from flask import Flask app = Flask(__name__) from TemperatureSensor import TemperatureSensor from Led import Led from flask import render_template lightr = Led(18) lightb = Led(24) pierre = TemperatureSensor() @app.route('/hello') def hello_world(): return 'Hello World!' @app.route('/') def index(): return render_template('base.html') @app.route('/<bleu_rouge>/<on_off>') def ledonb(bleu_rouge, on_off): if on_off == 'on' and bleu_rouge == 'bleu': lightb.on() elif on_off == 'off' and bleu_rouge == 'bleu': lightb.off()
from Database import Database import threading import Server # Setting variabili valoreMax = 27 pinSensore = 25 pinLed = 17 tipoSensore = Adafruit_DHT.DHT11 query = "INSERT INTO VALORI VALUES(?,?)" # Setting connessione al DB connessione = sqlite.connect("log.db") # Creazione oggetti led, sensore, database, condizionatore led = Led(pinLed, False) sensore = Sensore(tipoSensore, pinSensore) database = Database(connessione, connessione.cursor(), query) condizionatore = Condizionatore(sensore, led, database, valoreMax) # Setup Led condizionatore.led.setup() # Creazione e avvio del thread inerente al server server = threading.Thread(target=Server.avviaServer) server.start() # Istruzioni inerenti al processo di controllo temperatura while True: # In temp andrà il valore istantaneo della temperatura temp = condizionatore.sensore.getTemperatura()
def main(): score1 = 0 score2 = 0 server = 1 start_time = time.time() ## Graphics class screen = Screen(constants.WIDTH, constants.HEIGHT) player1 = Paddle(screen, 3, constants.HEIGHT / 2 - 1, constants.PADDLE_COLOUR) player2 = Paddle(screen, constants.WIDTH - 4, constants.HEIGHT / 2 - 1, constants.PADDLE_COLOUR) net = Net(screen, constants.NET_COLOUR) ball = Ball(screen, 5, 20, constants.BALL_COLOUR) led = Led(5) net.draw() screen.draw_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR) screen.draw_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR) # Dummy values ball.velocity = [10.0, 10.0] #Roughly 8 seconds to cross screen? while (True): end_time = time.time() frame_time = end_time - start_time start_time = end_time value1 = read_i2c(CHAN2) print(value1) value2 = read_i2c(CHAN3) if (GPIO.input(10) == 1): ball.served = True if (GPIO.input(9) == 1): player1.power_up() if (GPIO.input(17) == 0): ball.served = True if (GPIO.input(11) == 0): player2.power_up() # Lose condition if (ball.x >= screen.width - 1): score1 += 1 ball.served = False ball.x = player2.x - 1 ball.y = player2.y + player2.size[1] / 2 server = 2 screen.draw_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR) if (ball.x <= 1): score2 += 1 ball.served = False ball.x = player1.x + 1 ball.y = player1.y + player1.size[1] / 2 server = 1 screen.draw_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR) score1 %= 10 score2 %= 10 # TODO: Reduce noise; multiple reads before move? player1.move(value1) player2.move(value2) player1.update(frame_time) player2.update(frame_time) if (not ball.served): if (server == 1): ball.last_pos = [ball.roundx, ball.roundy] ball.y = player1.y + player1.size[1] / 2 ball.x = player1.x + 1 ball.roundx = int(round(ball.x)) ball.roundy = int(round(ball.y)) if (ball.last_pos != [ball.roundx, ball.roundy]): ball._moved = True if (server == 2): ball.last_pos = [ball.roundx, ball.roundy] ball.y = player2.y + player2.size[1] / 2 ball.x = player2.x - 1 ball.roundx = int(round(ball.x)) ball.roundy = int(round(ball.y)) if (ball.last_pos != [ball.roundx, ball.roundy]): ball._moved = True # Collision Detection if (ball.roundx == player1.x): rx = random.randint(5, 15) ry = random.randint(5, 15) if (ball.roundy >= player1.y and ball.roundy <= player1.y + player1.size[1] / 3): ball.velocity[1] = -ry ball.velocity[0] = rx if (ball.roundy >= player1.y + player1.size[1] / 3 and ball.roundy <= player1.y + player1.size[1] / 3 * 2): ball.velocity[1] = 0 ball.velocity[0] = rx if (ball.roundy >= player1.y + player1.size[1] / 3 * 2 and ball.roundy <= player1.y + player1.size[1]): ball.velocity[1] = ry ball.velocity[0] = rx if (ball.roundx == player2.x): rx = random.randint(5, 15) ry = random.randint(5, 15) if (ball.roundy >= player2.y and ball.roundy <= player2.y + player2.size[1] / 3): ball.velocity[1] = -ry ball.velocity[0] = -rx if (ball.roundy >= player2.y + player2.size[1] / 3 and ball.roundy <= player2.y + player2.size[1] / 3 * 2): ball.velocity[1] = 0 ball.velocity[0] = -rx if (ball.roundy >= player2.y + player2.size[1] / 3 * 2 and ball.roundy <= player2.y + player2.size[1]): ball.velocity[1] = ry ball.velocity[0] = -rx ball.update(frame_time) led.update(ball.x) player1.draw() player2.draw() ball.draw() net.spot_draw(ball.last_pos[0], ball.last_pos[1]) screen.spot_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR, ball.last_pos[0], ball.last_pos[1]) screen.spot_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR, ball.last_pos[0], ball.last_pos[1])
import RPi.GPIO as GPIO import time from flask_socketio import SocketIO, send, emit from Led import Led from Buzzer import Buzzer # //Initialisation de notre GPIO 17 pour recevoir un signal # //Contrairement à nos LEDs avec lesquelles on envoyait un signal lightblue = Led(24) lightred = Led(18) buzzer = Buzzer(22) class Mouvement(): def __init__(self, broche): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) self.broche = broche GPIO.setup(broche, GPIO.IN) def mouvement_loop(self, socketio): currentstate = 0 previousstate = 0 lightblue.on() while True: currentstate = GPIO.input(self.broche) if currentstate == 1 and previousstate == 0: previousstate = 1 lightblue.off() lightred.light_blink()
def main(): score1 = 0 score2 = 0 server = 1 won = 0 gameover = False effects_timer = 0 effects_count = 0 effects_colour = '' effect = False sound_timer = 0 start = True start_time = time.time() ## Graphics class screen = Screen(constants.WIDTH, constants.HEIGHT) player1 = Paddle(screen, 3, constants.HEIGHT/2-1, constants.PLAYER1_COLOUR) player2 = Paddle(screen, constants.WIDTH-4, constants.HEIGHT/2-1, constants.PLAYER2_COLOUR) net = Net(screen, constants.NET_COLOUR) ball = Ball(screen, 5, 20, constants.BALL_COLOUR) pyglow = PyGlow() led = Led(5) net.draw() screen.draw_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR) screen.draw_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR) # Initial value ball.velocity = [10.0,10.0] #Roughly 8 seconds to cross screen? screen.draw_str(25, 20, 'START', constants.WHITE) screen.draw_str(25, 26, 'GAME!', constants.WHITE) Buzzer.startMusic() while (True): # Calculate time since last frame end_time = time.time() frame_time = end_time - start_time start_time = end_time # Pyglow effects if (effect): effects_timer += frame_time if (won == 0): if ((effects_timer)%0.4 > 0.2 and (effects_timer - frame_time)%0.4 <= 0.2): pyglow.all(0) effects_count += 1 elif ((effects_timer)%0.4 <= 0.2 and (effects_timer - frame_time)%0.4 > 0.2): pyglow.color(effects_colour, 150) if (effects_count >= 5): effect = False effects_count = 0 else: if (effects_timer < 0.2): pyglow.color('white', 150) elif (effects_timer < 0.4): pyglow.color('blue', 150) elif (effects_timer < 0.6): pyglow.color('green', 150) elif (effects_timer < 0.8): pyglow.color('yellow', 150) elif (effects_timer < 1.0): pyglow.color('orange', 150) elif (effects_timer < 1.2): pyglow.color('red', 150) elif (effects_timer < 1.4): pyglow.all(0) pyglow.color('white', 150) effects_timer = 0 sound_timer += frame_time if (sound_timer / 0.15 >= 1): Buzzer.stopSound() sound_timer = 0 # Noise reduction for ADC value1 = 0 value2 = 0 for i in range(20): value1 += read_adc(CHAN2) value2 += read_adc(CHAN3) value1 /= 20 value2 /= 20 # Button inputs if (won == 0): # Hardware debounce # Player1 Serve if (GPIO.input(10) == 1): if (start): start = False screen.draw_str(25, 20, 'START', constants.BACKGROUND_COLOUR) screen.draw_str(25, 26, 'GAME!', constants.BACKGROUND_COLOUR) net.draw() time.sleep(0.2) ball.served = True start_time = time.time()-0.01 continue if (server == 1): ball.served = True # Player1 Power up if (GPIO.input(9) == 1 and not start): player1.power_up() # Software debounce # Player2 Serve if (read_adc(CHAN4) < 100): if (server == 2): ball.served = True # Player2 Power up if (debounce(1, 11) and not start): player2.power_up() # Lose condition if (ball.x >= screen.width-1): score1 += 1 ball.served = False # Draw new score screen.draw_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR) pyglow.color('blue', 150) effects_timer = 0 effects_colour = 'blue' effect = True # Work out who's turn to serve if ((score1+score2)%10 >= 5): server = 2 ball.x = player2.x-1 ball.y = player2.y + player2.size[1]/2 ball.velocity = [-10, 10] else: ball.x = player1.x+1 ball.y = player1.y + player1.size[1]/2 ball.velocity = [10, 10] # Lose condition if (ball.x <= 1): score2 += 1 ball.served = False # Draw new score screen.draw_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR) pyglow.color('red', 150) effects_timer = 0 effects_colour = 'red' effect = True # Work out who's turn to serve if ((score1+score2)%10 >= 5): server = 2 ball.x = player2.x-1 ball.y = player2.y + player2.size[1]/2 ball.velocity = [-10, 10] else: ball.x = player1.x+1 ball.y = player1.y + player1.size[1]/2 ball.velocity = [10, 10] # Has someone won? if (score1 >= 10): won = 1 elif (score2 >= 10): won = 2 # Move player paddles player1.move(value1) player2.move(value2) # Update paddles; if powerup player1.update(frame_time) player2.update(frame_time) # Move ball with paddle if not served if (not ball.served): if (server == 1): ball.last_pos = [ball.roundx, ball.roundy] ball.y = player1.y + player1.size[1] / 2 ball.x = player1.x + 1 ball.roundx = int(round(ball.x)) ball.roundy = int(round(ball.y)) if (ball.last_pos != [ball.roundx, ball.roundy]): ball._moved = True if (server == 2): ball.last_pos = [ball.roundx, ball.roundy] ball.y = player2.y + player2.size[1] / 2 ball.x = player2.x - 1 ball.roundx = int(round(ball.x)) ball.roundy = int(round(ball.y)) if (ball.last_pos != [ball.roundx, ball.roundy]): ball._moved = True # Collision Detection if (ball.roundx == player1.x): # Random speed rx = random.randint(5,15) ry = random.randint(5,15) # Different trajectories, depending on where the paddle was hit if (ball.roundy >= player1.y and ball.roundy <= player1.y + player1.size[1]/3): ball.velocity[1] = -ry ball.velocity[0] = rx Buzzer.hitSound() if (ball.roundy >= player1.y + player1.size[1]/3 and ball.roundy <= player1.y + player1.size[1]/3*2): ball.velocity[1] = 0 ball.velocity[0] = rx Buzzer.hitSound() if (ball.roundy >= player1.y + player1.size[1]/3*2 and ball.roundy <= player1.y + player1.size[1]): ball.velocity[1] = ry ball.velocity[0] = rx Buzzer.hitSound() # Redraw paddle player1._moved = True if (ball.roundx == player2.x): rx = random.randint(5,15) ry = random.randint(5,15) if (ball.roundy >= player2.y and ball.roundy <= player2.y + player2.size[1]/3): ball.velocity[1] = -ry ball.velocity[0] = -rx Buzzer.hitSound() if (ball.roundy >= player2.y + player2.size[1]/3 and ball.roundy <= player2.y + player2.size[1]/3*2): ball.velocity[1] = 0 ball.velocity[0] = -rx Buzzer.hitSound() if (ball.roundy >= player2.y + player2.size[1]/3*2 and ball.roundy <= player2.y + player2.size[1]): ball.velocity[1] = ry ball.velocity[0] = -rx Buzzer.hitSound() # Redraw paddle player2._moved = True # Update ball's position ball.update(frame_time) led.update(ball.x) # Draw ball ball.draw() # Draw player paddles player1.draw() player2.draw() # Draw net and score if ball was over them if (ball. last_pos != [ball.roundx, ball.roundy]): net.spot_draw(ball.last_pos[0], ball.last_pos[1]) screen.spot_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR, ball.last_pos[0], ball.last_pos[1]) screen.spot_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR, ball.last_pos[0], ball.last_pos[1]) # Print winner once if (won > 0 and not gameover): screen.draw_str(17, 20, 'PLAYER ' + str(won), constants.WHITE) screen.draw_str(25, 26, 'WINS!', constants.WHITE) gameover = True
class Domo: __navegador = None __sensorDeObjetos = None __testigoLuminoso = None __testigoSonoro = None __config = None __windowName = "Visor de Centrado" __domoMostrarMovimiento = False """ Ventana Eje (min,max) """ __ventanaX = None __ventanY = None """ Constructor """ def __init__(self, config): self.__config = config self.__navegador = Navegador(self.__config) self.__sensorDeObjetos = SensorDeObjetos( config.DomoPatronAReconocer, config.DomoCamaraId, config.DomoMostrarEnVentanaReconocimiento, config.DomoFotogramasXCaptura) self.__testigoLuminoso = Led() self.__testigoSonoro = Buzzer() if self.__config.DomoMostrarEnVentanaCentrado: cv.NamedWindow(self.__windowName, 1) self.__debugMode = self.__config.DomoDebugMode """ Destructor """ def __del__(self): if self.__config.DomoMostrarEnVentanaCentrado: cv.DestroyWindow(self.__windowName) """ Calcula las coordenadas de las ventanas una unica vez de acuerdo al tamano de la imagen """ def __calcularVentana(self): if self.__ventanaX == None and self.__ventanY == None: imgSize = self.__sensorDeObjetos.getImageSize() imgSizeX = imgSize[0] imgSizeY = imgSize[1] tmpPrincipio = int( (imgSizeX - self.__config.DomoVentanaHorizontal) / 2) tmpFin = imgSizeX - tmpPrincipio self.__ventanaX = (tmpPrincipio, tmpFin) tmpPrincipio = int( (imgSizeY - self.__config.DomoVentanaVertical) / 2) tmpFin = imgSizeY - tmpPrincipio self.__ventanaY = (tmpPrincipio, tmpFin) """ Posiciona el Domo """ def posicionar(self): self.__sensorDeObjetos.capturar() self.__calcularVentana() if self.__sensorDeObjetos.haveObjects(): self.__testigoLuminoso.encender() if self.__config.DomoMover: self.__posicionar() else: self.__testigoLuminoso.apagar() """ Calcula la posicion """ def __posicionar(self): coordenadas = self.__sensorDeObjetos.getObjectPosition() """ ((x, y, w, h), n) """ x = coordenadas[0] y = coordenadas[1] w = coordenadas[2] h = coordenadas[3] n = coordenadas[4] cx = int(x + (w / 2)) cy = int(y + (h / 2)) mov = self.__calcularMovimientoDomo(x, y, w, h, n, cx, cy) movX = mov[0] movY = mov[1] movZ = mov[2] if self.__config.DomoMostrarEnVentanaCentrado: self.__mostrarCentradoEnVentana(cx, cy, movX, movY) self.__realizarMovimientos(movX, movY, movZ) """ Muestra una imagen con la 'Ventana' para la imagen """ def __mostrarCentradoEnVentana(self, cx, cy, movX, movY): tmpImage = self.__sensorDeObjetos.getImage() cv.Circle(tmpImage, (cx, cy), 3, cv.RGB(255, 0, 0)) cv.Line(tmpImage, (self.__ventanaX[0], 0), (self.__ventanaX[0], tmpImage.height), cv.RGB(255, 0, 0)) cv.Line(tmpImage, (self.__ventanaX[1], 0), (self.__ventanaX[1], tmpImage.height), cv.RGB(255, 0, 0)) cv.Line(tmpImage, (0, self.__ventanaY[0]), (tmpImage.width, self.__ventanaY[0]), cv.RGB(255, 0, 0)) cv.Line(tmpImage, (0, self.__ventanaY[1]), (tmpImage.width, self.__ventanaY[1]), cv.RGB(255, 0, 0)) imgCenterX = int(tmpImage.width / 2) imgCenterY = int(tmpImage.height / 2) cv.Circle(tmpImage, (imgCenterX, imgCenterY), 3, cv.RGB(0, 0, 255)) if self.__debugMode: print movX, movY cv.Line(tmpImage, (imgCenterX, imgCenterY), (imgCenterX + (movX * self.__config.DomoPixelesPorMovimientoDebugLineX), imgCenterY), cv.RGB(0, 0, 255)) cv.Line(tmpImage, (imgCenterX, imgCenterY), (imgCenterX, imgCenterY + (movY * self.__config.DomoPixelesPorMovimientoDebugLineX)), cv.RGB(0, 0, 255)) """cv.SaveImage("ImagenCentrado.jpg", tmpImage)""" cv.ShowImage(self.__windowName, tmpImage) return cv.WaitKey(10) <= 0 """ Calcula el moviemiento del domo """ def __calcularMovimientoDomo(self, x, y, w, h, n, cx, cy): return (self.__calcularCantidadMoviemientoEje(self.__ventanaX, cx), self.__calcularCantidadMoviemientoEje(self.__ventanaY, cy), self.__calcularCantidadMoviemientoDistancia(w)) """ Realiza el moviemiento del domo """ def __realizarMovimientos(self, movX, movY, movZ): self.__navegador.mover(movX, movY, movZ) """ Devuelve la cantidad de movimientos que hay que realizar para centrar el Objeto """ def __calcularCantidadMoviemientoEje(self, ventana, centroFigura): centroFronteraPrincipio = ventana[0] centroFronteraFin = ventana[1] if centroFigura < centroFronteraPrincipio: return self.__pixelesAMovimiento(centroFigura - centroFronteraPrincipio) elif centroFigura > centroFronteraFin: return self.__pixelesAMovimiento(centroFigura - centroFronteraFin) else: return 0 """ Devuelve la cantidad de movimientos que hay que realizar para centrar el Objeto en Z """ def __calcularCantidadMoviemientoDistancia(self, width): minimo = self.__config.DomoVentanaDistanciaMinima maximo = self.__config.DomoVentanaDistanciaMaxima if width < minimo: return minimo - width elif width > maximo: return maximo - width else: return 0 """ Devuelve la cantidad de movimientos que implica la cantidad de pixeles pasada """ def __pixelesAMovimiento(self, pixeles): return int(round(pixeles / self.__config.DomoPixelesPorMovimiento))
self.pulseaudio_set_volume("-5") elif (button == 6): #mouse wheel up self.pulseaudio_set_volume("+5") else: print("Invalid event number", button, file=sys.stderr) if not keep_led: self.led.set_value(led_value) if __name__ == '__main__': try: #get file descriptor to led file before possible privilege drop led = None if response_led_file != "": try: led = Led(os.open(response_led_file, os.O_RDWR)) except: raise OSError("Response led file could not be opened") led.set_value(False) print("Response led file opened") else: print("No response led file given, feature disabled") daemon = MouseDaemon(mouse_file=mouse_file, switch_user=switch_user, user=user_name, group=group_name) responder = PulseAudioMouseEventResponder(sink, sink_no, max_vol, min_vol, led) daemon.handleEvents(responder) except Exception as e: print(e, file=sys.stderr) sys.exit(1)
__author__ = 'Thomas Kaland' # _*_ coding: utf-8 _*_ from Servo import Lid from Led import Led from Circuit import Magnet, Solution from TellArduino import TellArduino from Sound import Sound import random import time TestMode = True #Setter opp klasser til test2 led = Led([21, 16, 25, 12, 20]) #Setter opp klasse som styrer led-lys test2Solution = Solution([11, 9, 10, 24, 23], [19, 26], [6, 13], [3000, 1000, 2000, 1000, 500], 12) test2Magnet = Magnet([8]) PossibleSolutions = [3, 4, 6] #Setter opp klasser til test1 test1Solution = Solution([], [27, 17], [22, 5], [], 24) test1Magnet = Magnet([7]) #Setter opp generelle klasser Arduino = TellArduino('/dev/ttyACM0') #Lydfiler: Correct = Sound('correct.wav') Powerup = Sound('powerup.wav') Down = Sound('down.wav')
import time from Led import Led from time import sleep from flask import Flask from flask_socketio import SocketIO, send, emit from flask import render_template import threading app = Flask(__name__) socketio = SocketIO(app) is_running = True is_blinking = False GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) led = Led(24) # Initialisation de notre GPIO 17 pour recevoir un signal # Contrairement à nos LEDs avec lesquelles on envoyait un signal def stop_the_cat(): buzzer = 22 GPIO.setup(buzzer, GPIO.OUT) broche=17 GPIO.setup(broche, GPIO.IN) global is_blinking is_blinking= False currentstate = 0 previousstate = 0 # Boucle infini jusqu'à CTRL-C if is_running==True: while is_running:
from board import Board from Led import Led from temp2 import Temperature from Rgb import RGB_Led from LCD1602 import LCD1602 from time import sleep from button import Button from buzzer import Buzzer from pir import Pir rpi = Board() led = Led(rpi,11) rgb = RGB_Led(26, 19, 13) button = Button(rpi, 27) temp = Temperature() lcd = LCD1602(rpi) buzzer = Buzzer() pir = Pir while True: if lcd.message()
from Led import Led import time # button = Led(13); #Yellow # button = Led(4); #GREEN # button = Led(18); #Red button = Led(17) #BLUE while True: # print("ciao"); button.on() time.sleep(0.1) button.off() time.sleep(0.1)
class demo: def __init__(self, pin_led, pin_sw, debug=False): self.pin_led = pin_led self.pin_sw = pin_sw self.long_press = [ {'timeout':0.7, 'blink':{'on':1, 'off':0}}, {'timeout':1, 'blink':{'on':0.2, 'off':0.04}}, {'timeout':3, 'blink':{'on':0.1, 'off':0.04}}, {'timeout':5, 'blink':{'on':0.04, 'off':0.04}}, {'timeout':7, 'blink':{'on':0, 'off':0}}] self.timeout_sec = [] for i in range(len(self.long_press)): self.timeout_sec.append(self.long_press[i]['timeout']) self.sw = SwitchListener([self.pin_sw], self.sw_callback, timeout_sec=self.timeout_sec, debug=debug) self.led = Led(self.pin_led) self.active = True def main(self): start_sec = time.time() while self.active: print('main> %.1f' % ((time.time() - start_sec))) time.sleep(1) self.led.off() def sw_callback(self, sw, event): event.print() if event.name == 'pressed': self.led.on() if event.name == 'released': self.led.off() if event.name == 'timer': idx = event.timeout_idx if idx == 0: # マルチクリック回数確定 if event.value == Switch.OFF: self.led.off() for i in range(event.push_count): time.sleep(0.4) self.led.on() time.sleep(0.4) self.led.off() if idx >= 1: # 長押し if idx < len(self.long_press) - 1: self.led.off() self.led.blink(self.long_press[idx]['blink']['on'], self.long_press[idx]['blink']['off']) else: self.led.off() self.active = False
from Camera import Camera from Logger import Logger from Led import Led from Sonic import Sonic import time #init camera = Camera() led = Led() logger = Logger() sonic = Sonic() #start logger.info("Starting program") #red led logger.info("Turning red led on") led.turnLedOn("red") #start capturing condition = True logger.info("Reading distance") try: while condition: distance = sonic.getDistance() logger.debug("Reading distance => {dist}".format(dist=distance)) time.sleep(1) if distance >= 30 and distance <= 120: camera.captureImage() camera.recognizePlate()
class Relay: """Relay object""" def __init__(self, name): self.name = name self.settings = None self.rSettings = None self.button = None self.led = None self.pin = None self.pinNr = None self.on = 1 self.off = 0 self.last_change = 0 self.min_time_change = 500 def setup(self): self.settings = SettingsSingleton.getInstance() self.rSettings = self.settings.getRelaySettings(self.name) if not self.rSettings: print('Relay settings are incorrect!') sys.exit(1) try: self.pinNr = self.rSettings["relay_pin"] except: print('Relay pin number is missing!') sys.exit(1) if not (self.pinNr >= 0): print('Relay pin number is incorrect!') sys.exit(1) invertState = "false" try: invertState = self.rSettings["invert"] if not (invertState == "false"): self.off = 1 self.on = 0 except: pass try: self.min_time_change = self.settings.get('button_pressed_time') except: pass self.pin = machine.Pin(self.pinNr, machine.Pin.OUT) self.pin.value(self.off) try: button_pin = self.rSettings["button_pin"] self.button = Button(button_pin) self.button.setup() except: # no button for this relay pass led_default_state = 0 try: led_default_state = self.rSettings["default_led_state"] except: pass try: led_pin = self.rSettings["led_pin"] self.led = Led(led_pin, led_default_state) self.led.setup() except: # no led for this relay pass def set_state(self, new_state): if not self.allow_change(): return None self.last_change = time.ticks_ms() if new_state is 1: self.pin.value(self.on) if self.led is not None: self.led.start_blink() return 1 if new_state is 0: self.pin.value(self.off) if self.led is not None: self.led.stop_blink() return 0 def get_state(self): return self.pin.value() def toggle_state(self): actual_state = self.pin.value() if actual_state is self.on: return self.set_state(0) if actual_state is self.off: return self.set_state(1) def check_button(self): if self.button.get_state() is True: if not self.allow_change(): self.button.state_read() return None self.button.state_read() return self.toggle_state() def allow_change(self): if not ((time.ticks_ms() - self.last_change) > self.min_time_change): return False return True def get_name(self): return self.name
def main(): score1 = 9 score2 = 0 server = 1 won = 0 gameover = False effects_timer = 0 effects_count = 0 effects_colour = '' effect = False start = True start_time = time.time() ## Graphics class screen = Screen(constants.WIDTH, constants.HEIGHT) player1 = Paddle(screen, 3, constants.HEIGHT / 2 - 1, constants.PLAYER1_COLOUR) player2 = Paddle(screen, constants.WIDTH - 4, constants.HEIGHT / 2 - 1, constants.PLAYER2_COLOUR) net = Net(screen, constants.NET_COLOUR) ball = Ball(screen, 5, 20, constants.BALL_COLOUR) pyglow = PyGlow() led = Led(5) net.draw() screen.draw_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR) screen.draw_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR) # Initial value ball.velocity = [10.0, 10.0] #Roughly 8 seconds to cross screen? screen.draw_str(25, 20, 'START', constants.WHITE) screen.draw_str(25, 26, 'GAME!', constants.WHITE) while (True): end_time = time.time() frame_time = end_time - start_time start_time = end_time if (effect): effects_timer += frame_time if ((effects_timer) % 0.4 > 0.2 and (effects_timer - frame_time) % 0.4 <= 0.2): pyglow.all(0) effects_count += 1 elif ((effects_timer) % 0.4 <= 0.2 and (effects_timer - frame_time) % 0.4 > 0.2): pyglow.color(effects_colour, 150) if (effects_count >= 5): effect = False effects_count = 0 #noise reduction value1 = 0 value2 = 0 for i in range(20): value1 += read_i2c(CHAN2) value2 += read_i2c(CHAN3) value1 /= 20 value2 /= 20 if (won == 0): # Hardware debounce # Player1 Serve if (GPIO.input(10) == 1): if (start): start = False screen.draw_str(25, 20, 'START', constants.BACKGROUND_COLOUR) screen.draw_str(25, 26, 'GAME!', constants.BACKGROUND_COLOUR) net.draw() if (server == 1): ball.served = True # Player1 Power up if (GPIO.input(9) == 1): player1.power_up() # Software debounce # Player2 Serve if (debounce(0, 17)): if (server == 2): ball.served = True # Player2 Power up if (debounce(1, 11)): player2.power_up() # Lose condition if (ball.x >= screen.width - 1): score1 += 1 ball.served = False screen.draw_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR) pyglow.color('blue', 150) effects_timer = 0 effects_colour = 'blue' effect = True if ((score1 + score2) % 10 >= 5): server = 2 ball.x = player2.x - 1 ball.y = player2.y + player2.size[1] / 2 ball.velocity = [-10, 10] else: ball.x = player1.x + 1 ball.y = player1.y + player1.size[1] / 2 ball.velocity = [10, 10] if (ball.x <= 1): score2 += 1 ball.served = False ball.x = player1.x + 1 ball.y = player1.y + player1.size[1] / 2 screen.draw_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR) pyglow.color('red', 150) effects_timer = 0 effects_colour = 'red' effect = True if ((score1 + score2) % 10 >= 5): server = 2 ball.x = player2.x - 1 ball.y = player2.y + player2.size[1] / 2 ball.velocity = [-10, 10] else: ball.x = player1.x + 1 ball.y = player1.y + player1.size[1] / 2 ball.velocity = [10, 10] if (score1 >= 10): won = 1 elif (score2 >= 10): won = 2 # TODO: Reduce noise; multiple reads before move? player1.move(value1) player2.move(value2) player1.update(frame_time) player2.update(frame_time) if (not ball.served): if (server == 1): ball.last_pos = [ball.roundx, ball.roundy] ball.y = player1.y + player1.size[1] / 2 ball.x = player1.x + 1 ball.roundx = int(round(ball.x)) ball.roundy = int(round(ball.y)) if (ball.last_pos != [ball.roundx, ball.roundy]): ball._moved = True if (server == 2): ball.last_pos = [ball.roundx, ball.roundy] ball.y = player2.y + player2.size[1] / 2 ball.x = player2.x - 1 ball.roundx = int(round(ball.x)) ball.roundy = int(round(ball.y)) if (ball.last_pos != [ball.roundx, ball.roundy]): ball._moved = True # Collision Detection if (ball.roundx == player1.x): rx = random.randint(5, 15) ry = random.randint(5, 15) if (ball.roundy >= player1.y and ball.roundy <= player1.y + player1.size[1] / 3): ball.velocity[1] = -ry ball.velocity[0] = rx if (ball.roundy >= player1.y + player1.size[1] / 3 and ball.roundy <= player1.y + player1.size[1] / 3 * 2): ball.velocity[1] = 0 ball.velocity[0] = rx if (ball.roundy >= player1.y + player1.size[1] / 3 * 2 and ball.roundy <= player1.y + player1.size[1]): ball.velocity[1] = ry ball.velocity[0] = rx # Redraw paddle player1._moved = True if (ball.roundx == player2.x): rx = random.randint(5, 15) ry = random.randint(5, 15) if (ball.roundy >= player2.y and ball.roundy <= player2.y + player2.size[1] / 3): ball.velocity[1] = -ry ball.velocity[0] = -rx if (ball.roundy >= player2.y + player2.size[1] / 3 and ball.roundy <= player2.y + player2.size[1] / 3 * 2): ball.velocity[1] = 0 ball.velocity[0] = -rx if (ball.roundy >= player2.y + player2.size[1] / 3 * 2 and ball.roundy <= player2.y + player2.size[1]): ball.velocity[1] = ry ball.velocity[0] = -rx # Redraw paddle player2._moved = True ball.update(frame_time) led.update(ball.x) ball.draw() player1.draw() player2.draw() net.spot_draw(ball.last_pos[0], ball.last_pos[1]) screen.spot_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR, ball.last_pos[0], ball.last_pos[1]) screen.spot_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR, ball.last_pos[0], ball.last_pos[1]) if (won > 0 and not gameover): screen.draw_str(15, 20, 'PLAYER ' + str(won), constants.WHITE) screen.draw_str(25, 26, 'WINS!', constants.WHITE) gameover = True
def __init__(self): self.db = Database() self.camera = PiCamera() self.led = Led() self.logger = Logger()
return True else: bm.startBehavior(nome) return True except Exception as e: print("Exception -> Comportamento.iniciar():", e) return False @staticmethod def parar(nome, posturaCrouch=True, async=False): try: if async: return AsyncThread.call( lambda: Comportamento.parar(nome, posturaCrouch, False)) if nome in Comportamento.listar(): Led.corpoVermelho(255) bm = Comportamento.conn() bm.stopBehavior(nome) if posturaCrouch: Motor.posturaCrouch() else: time.sleep(1) Led.corpoVerde(255) time.sleep(1) Led.corpo(255, 255, 255) return True except Exception as e: print("Exception -> Comportamento.parar():", e) return False @staticmethod
import io import os import socket import struct import time import picamera import sys from Ultrasonic import Ultrasonic from servo import Servo from Motor import Motor from Buzzer import Buzzer from Led import Led, Color led = Led() buzzer = Buzzer() pwm = Servo() ultrasonic = Ultrasonic() motor = Motor() MIDDLE_ANGLE = 90 DELTA = 35 DATA_PTS = 2 SPEED = 900 TURNING_SPEED = 1500 def setMotor(distances, counter): # if min(distances) < 15: # motor.setMotorModel(0, 0, 0, 0) # buzzer.run('1') # return left = distances[:DATA_PTS]
def setupUi(self, IcePapDriverWidget): IcePapDriverWidget.setObjectName("IcePapDriverWidget") IcePapDriverWidget.resize(100, 201) IcePapDriverWidget.setMinimumSize(QtCore.QSize(100, 201)) IcePapDriverWidget.setMaximumSize(QtCore.QSize(120, 220)) self.vboxlayout = QtGui.QVBoxLayout(IcePapDriverWidget) self.vboxlayout.setSpacing(2) self.vboxlayout.setMargin(2) self.vboxlayout.setObjectName("vboxlayout") self.frame = QtGui.QFrame(IcePapDriverWidget) self.frame.setMinimumSize(QtCore.QSize(90, 190)) self.frame.setMaximumSize(QtCore.QSize(90, 190)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(16, 16, 16)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(239, 235, 231)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(237, 237, 237)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(247, 245, 243)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(119, 117, 115)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(159, 157, 154)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(16, 16, 16)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(16, 16, 16)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(239, 235, 231)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(101, 148, 235)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Highlight, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.HighlightedText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Link, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.LinkVisited, brush) brush = QtGui.QBrush(QtGui.QColor(247, 245, 243)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(16, 16, 16)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(239, 235, 231)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(237, 237, 237)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(247, 245, 243)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(119, 117, 115)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(159, 157, 154)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(16, 16, 16)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(16, 16, 16)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(239, 235, 231)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(101, 148, 235)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Highlight, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.HighlightedText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Link, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.LinkVisited, brush) brush = QtGui.QBrush(QtGui.QColor(247, 245, 243)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(127, 125, 123)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(239, 235, 231)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(237, 237, 237)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(247, 245, 243)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(119, 117, 115)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(159, 157, 154)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(127, 125, 123)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(127, 125, 123)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(239, 235, 231)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(84, 123, 196)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Highlight, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.HighlightedText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Link, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.LinkVisited, brush) brush = QtGui.QBrush(QtGui.QColor(247, 245, 243)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase, brush) self.frame.setPalette(palette) self.frame.setFrameShape(QtGui.QFrame.StyledPanel) self.frame.setFrameShadow(QtGui.QFrame.Raised) self.frame.setObjectName("frame") self.gridlayout = QtGui.QGridLayout(self.frame) self.gridlayout.setMargin(3) self.gridlayout.setSpacing(3) self.gridlayout.setObjectName("gridlayout") self.lblName = QtGui.QLabel(self.frame) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(0, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(239, 235, 231)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(237, 237, 237)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(247, 245, 243)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(119, 117, 115)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(159, 157, 154)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(16, 16, 16)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(239, 235, 231)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(16, 16, 16)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Highlight, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.HighlightedText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Link, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.LinkVisited, brush) brush = QtGui.QBrush(QtGui.QColor(247, 245, 243)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(239, 235, 231)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(237, 237, 237)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(247, 245, 243)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(119, 117, 115)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(159, 157, 154)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(16, 16, 16)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(239, 235, 231)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(16, 16, 16)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Highlight, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.HighlightedText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Link, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.LinkVisited, brush) brush = QtGui.QBrush(QtGui.QColor(247, 245, 243)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(127, 125, 123)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(239, 235, 231)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(237, 237, 237)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(247, 245, 243)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(119, 117, 115)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(159, 157, 154)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(127, 125, 123)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(127, 125, 123)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(239, 235, 231)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(127, 125, 123)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Highlight, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.HighlightedText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Link, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.LinkVisited, brush) brush = QtGui.QBrush(QtGui.QColor(247, 245, 243)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase, brush) self.lblName.setPalette(palette) self.lblName.setAlignment(QtCore.Qt.AlignCenter) self.lblName.setObjectName("lblName") self.gridlayout.addWidget(self.lblName, 1, 0, 1, 2) self.textLabel1 = QtGui.QLabel(self.frame) font = QtGui.QFont() font.setFamily("Sans Serif") font.setPointSize(8) font.setWeight(50) font.setItalic(False) font.setUnderline(False) font.setStrikeOut(False) font.setBold(False) self.textLabel1.setFont(font) self.textLabel1.setObjectName("textLabel1") self.gridlayout.addWidget(self.textLabel1, 2, 0, 1, 2) self.lcdCurrent = QtGui.QLCDNumber(self.frame) font = QtGui.QFont() font.setFamily("Sans Serif") font.setPointSize(15) font.setWeight(50) font.setItalic(False) font.setUnderline(False) font.setStrikeOut(False) font.setBold(False) self.lcdCurrent.setFont(font) self.lcdCurrent.setSmallDecimalPoint(True) self.lcdCurrent.setNumDigits(3) self.lcdCurrent.setSegmentStyle(QtGui.QLCDNumber.Flat) self.lcdCurrent.setObjectName("lcdCurrent") self.gridlayout.addWidget(self.lcdCurrent, 3, 0, 1, 2) self.textLabel1_2 = QtGui.QLabel(self.frame) font = QtGui.QFont() font.setFamily("Sans Serif") font.setPointSize(8) font.setWeight(50) font.setItalic(False) font.setUnderline(False) font.setStrikeOut(False) font.setBold(False) self.textLabel1_2.setFont(font) self.textLabel1_2.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.textLabel1_2.setObjectName("textLabel1_2") self.gridlayout.addWidget(self.textLabel1_2, 4, 1, 1, 1) self.ledStatus = Led(self.frame) self.ledStatus.setObjectName("ledStatus") self.gridlayout.addWidget(self.ledStatus, 4, 0, 1, 1) self.textLabel1_2_2 = QtGui.QLabel(self.frame) font = QtGui.QFont() font.setFamily("Sans Serif") font.setPointSize(8) font.setWeight(50) font.setItalic(False) font.setUnderline(False) font.setStrikeOut(False) font.setBold(False) self.textLabel1_2_2.setFont(font) self.textLabel1_2_2.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.textLabel1_2_2.setObjectName("textLabel1_2_2") self.gridlayout.addWidget(self.textLabel1_2_2, 5, 1, 1, 1) self.ledLimitPos = Led(self.frame) self.ledLimitPos.setObjectName("ledLimitPos") self.gridlayout.addWidget(self.ledLimitPos, 5, 0, 1, 1) self.ledLimitNeg = Led(self.frame) self.ledLimitNeg.setObjectName("ledLimitNeg") self.gridlayout.addWidget(self.ledLimitNeg, 6, 0, 1, 1) self.textLabel1_2_2_2 = QtGui.QLabel(self.frame) font = QtGui.QFont() font.setFamily("Sans Serif") font.setPointSize(8) font.setWeight(50) font.setItalic(False) font.setUnderline(False) font.setStrikeOut(False) font.setBold(False) self.textLabel1_2_2_2.setFont(font) self.textLabel1_2_2_2.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.textLabel1_2_2_2.setObjectName("textLabel1_2_2_2") self.gridlayout.addWidget(self.textLabel1_2_2_2, 6, 1, 1, 1) self.pushButton = QtGui.QPushButton(self.frame) self.pushButton.setMaximumSize(QtCore.QSize(16777215, 20)) self.pushButton.setCheckable(True) self.pushButton.setFlat(False) self.pushButton.setObjectName("pushButton") self.gridlayout.addWidget(self.pushButton, 7, 0, 1, 2) self.label = QtGui.QLabel(self.frame) self.label.setPixmap( QtGui.QPixmap(":/logos/IcepapCfg Icons/Icepapdriverpetit.png")) self.label.setAlignment(QtCore.Qt.AlignCenter) self.label.setObjectName("label") self.gridlayout.addWidget(self.label, 0, 0, 1, 2) self.vboxlayout.addWidget(self.frame) self.retranslateUi(IcePapDriverWidget) QtCore.QMetaObject.connectSlotsByName(IcePapDriverWidget)
from Led import Led from flask import render_template from flask import Flask app = Flask(__name__) lightr = Led(14) lightb = Led(15) @app.route('/hello') def hello_world(): return 'Hello World!' @app.route('/') def index(): return render_template('base.html') @app.route('/<bleu_rouge>/<on_off>') def ledonb(bleu_rouge, on_off): if on_off == 'on' and bleu_rouge == 'bleu': lightb.on() elif on_off == 'off' and bleu_rouge == 'bleu': lightb.off() elif on_off == 'on' and bleu_rouge == 'rouge': lightr.on() elif on_off == 'off' and bleu_rouge == 'rouge':