Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Created by Edoardo La Greca
- '''
- from sense_emu import SenseHat
- from time import sleep
- s = SenseHat()
- # Colori
- red = (255, 0, 0) # Da 22.5 in poi
- blue = (0, 0, 255) # Fino a 21.5
- white = (255, 255, 255) # Da 21.5 a 22.5
- # Temperatura iniziale ricavata dal sensore della SenseHAT
- initTemp = s.get_temperature()
- # Stanza iniziale da mostrare (per non avere errori con
- # l'array, usa 0 anche se รจ la stanza 1)
- room = 0
- # Array contenente la temperatura delle stanze
- roomsTemp = [initTemp, initTemp, initTemp]
- # Fixa il bug per cui il metodo assegnato al movimento del joystick (sull'emulatore)
- # viene eseguito due volte
- emuButton = 0
- # In base alla temperatura dice quale colore deve mostrare
- def whichColor(t):
- if t < 21.5:
- return "blue"
- elif t >= 21.5 and t <= 22.5:
- return "white"
- elif t > 22.5:
- return "red"
- # Imposta tutti i pixel come blu
- def setAllBlue():
- for x in range(0, 8):
- for y in range(0, 8):
- s.set_pixel(x, y, blue)
- # Imposta tutti i pixel come bianchi
- def setAllWhite():
- for x in range(0, 8):
- for y in range(0, 8):
- s.set_pixel(x, y, white)
- # Imposta tutti i pixel come rossi
- def setAllRed():
- for x in range(0, 8):
- for y in range(0, 8):
- s.set_pixel(x, y, red)
- # Quando il joystick (js) punta verso destra
- def js_Right():
- if (emuButton == 1):
- # UnboundLocalError: local variable referenced before assignment
- global room
- print(str(room))
- # Cambia stanza
- if room == 0 or room == 1:
- room += 1
- else:
- room = 0
- emuButton = 0
- # Mostra il numero della stanza
- s.show_letter(str(room + 1))
- sleep(1)
- else:
- emubutton += 1
- # Quando il joystick (js) punta verso sinistra
- def js_Left():
- if (emuButton == 1):
- # UnboundLocalError: local variable referenced before assignment
- global room
- # Cambia stanza
- if room == 1 or room == 2:
- room -= 1
- else:
- room = 2
- emuButton = 0
- # Mostra il numero della stanza
- s.show_letter(str(room + 1))
- sleep(1)
- else:
- emubutton += 1
- # Quando il joystick (js) viene usato
- def js_Any():
- global roomsTemp
- # Aggiorna la temperatura
- roomsTemp[room] = s.get_temperature()
- # Mostra il colore in base alla temperatura
- if whichColor(roomsTemp[room]) == "blue":
- setAllBlue()
- elif whichColor(roomsTemp[room]) == "white":
- setAllWhite()
- elif whichColor(roomsTemp[room]) == "red":
- setAllRed()
- s.clear()
- # Mostra il numero della stanza iniziale
- s.show_letter(str(room + 1))
- sleep(1)
- # Mostra il colore in base alla temperatura
- if whichColor(roomsTemp[room]) == "blue":
- setAllBlue()
- elif whichColor(roomsTemp[room]) == "white":
- setAllWhite()
- elif whichColor(roomsTemp[room]) == "red":
- setAllRed()
- # Eventi per il movimento del joystick
- s.stick.direction_right = js_Right
- s.stick.direction_left = js_Left
- s.stick.direction_any = js_Any
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement