Advertisement
Guest User

laggone!!!!!!!

a guest
Mar 13th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.19 KB | None | 0 0
  1. '''
  2.  
  3. Created by Edoardo La Greca
  4.  
  5. '''
  6.  
  7. from sense_emu import SenseHat
  8. from time import sleep
  9.  
  10. s = SenseHat()
  11.  
  12. # Colori
  13. red = (255, 0, 0)       # Da 22.5 in poi
  14. blue = (0, 0, 255)      # Fino a 21.5
  15. white = (255, 255, 255) # Da 21.5 a 22.5
  16.  
  17. # Temperatura iniziale ricavata dal sensore della SenseHAT
  18. initTemp = s.get_temperature()
  19.  
  20. # Stanza iniziale da mostrare (per non avere errori con
  21. # l'array, usa 0 anche se รจ la stanza 1)
  22. room = 0
  23.  
  24. # Array contenente la temperatura delle stanze
  25. roomsTemp = [initTemp, initTemp, initTemp]
  26.  
  27. # Fixa il bug per cui il metodo assegnato al movimento del joystick (sull'emulatore)
  28. # viene eseguito due volte
  29. emuButton = 0
  30.  
  31. # In base alla temperatura dice quale colore deve mostrare
  32. def whichColor(t):
  33.     if t < 21.5:
  34.         return "blue"
  35.     elif t >= 21.5 and t <= 22.5:
  36.         return "white"
  37.     elif t > 22.5:
  38.         return "red"
  39.  
  40. # Imposta tutti i pixel come blu
  41. def setAllBlue():
  42.     for x in range(0, 8):
  43.         for y in range(0, 8):
  44.             s.set_pixel(x, y, blue)
  45.  
  46. # Imposta tutti i pixel come bianchi
  47. def setAllWhite():
  48.     for x in range(0, 8):
  49.         for y in range(0, 8):
  50.             s.set_pixel(x, y, white)
  51.  
  52. # Imposta tutti i pixel come rossi
  53. def setAllRed():
  54.     for x in range(0, 8):
  55.         for y in range(0, 8):
  56.             s.set_pixel(x, y, red)
  57.  
  58. # Quando il joystick (js) punta verso destra
  59. def js_Right():
  60.     global emuButton
  61.  
  62.     if (emuButton == 1):
  63.         # UnboundLocalError: local variable referenced before assignment
  64.         global room
  65.         print(str(room))
  66.  
  67.         # Cambia stanza
  68.         if room == 0 or room == 1:
  69.             room += 1
  70.         else:
  71.             room = 0
  72.  
  73.         emuButton = 0
  74.  
  75.         # Mostra il numero della stanza
  76.         s.show_letter(str(room + 1))
  77.         sleep(1)
  78.     else:
  79.         emubutton += 1
  80.  
  81. # Quando il joystick (js) punta verso sinistra
  82. def js_Left():
  83.     global emuButton
  84.    
  85.     if (emuButton == 1):
  86.         # UnboundLocalError: local variable referenced before assignment
  87.         global room
  88.  
  89.         # Cambia stanza
  90.         if room == 1 or room == 2:
  91.             room -= 1
  92.         else:
  93.             room = 2
  94.  
  95.         emuButton = 0
  96.  
  97.         # Mostra il numero della stanza
  98.         s.show_letter(str(room + 1))
  99.         sleep(1)
  100.     else:
  101.         emubutton += 1
  102.  
  103. # Quando il joystick (js) viene usato
  104. def js_Any():
  105.     global roomsTemp
  106.  
  107.     # Aggiorna la temperatura
  108.     roomsTemp[room] = s.get_temperature()
  109.  
  110.     # Mostra il colore in base alla temperatura
  111.     if whichColor(roomsTemp[room]) == "blue":
  112.         setAllBlue()
  113.     elif whichColor(roomsTemp[room]) == "white":
  114.         setAllWhite()
  115.     elif whichColor(roomsTemp[room]) == "red":
  116.         setAllRed()
  117.  
  118. s.clear()
  119.  
  120. # Mostra il numero della stanza iniziale
  121. s.show_letter(str(room + 1))
  122. sleep(1)
  123.  
  124. # Mostra il colore in base alla temperatura
  125. if whichColor(roomsTemp[room]) == "blue":
  126.     setAllBlue()
  127. elif whichColor(roomsTemp[room]) == "white":
  128.     setAllWhite()
  129. elif whichColor(roomsTemp[room]) == "red":
  130.     setAllRed()
  131.  
  132. # Eventi per il movimento del joystick
  133. s.stick.direction_right = js_Right
  134. s.stick.direction_left = js_Left
  135. s.stick.direction_any = js_Any
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement