Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3.  
  4. import json
  5. import sys
  6. import getopt
  7. import linecache
  8.  
  9. from sense_emu import SenseHat, ACTION_PRESSED, ACTION_HELD, ACTION_RELEASED
  10. from signal import pause
  11.  
  12. x = 0
  13. y = 0
  14. z = 0
  15. sense = SenseHat()
  16.  
  17. while True:
  18.    
  19.     def pushed_up(event):
  20.         global y
  21.         if event.action != ACTION_RELEASED:
  22.             y = y + 1
  23.  
  24.     def pushed_down(event):
  25.         global y
  26.         if event.action != ACTION_RELEASED:
  27.             y = y - 1
  28.  
  29.     def pushed_left(event):
  30.         global x
  31.         if event.action != ACTION_RELEASED:
  32.             x = x - 1
  33.  
  34.     def pushed_right(event):
  35.         global x
  36.         if event.action != ACTION_RELEASED:
  37.             x = x + 1
  38.     def pushed_middle(event):
  39.         global z
  40.         if event.action != ACTION_RELEASED:
  41.             z = z + 1
  42.            
  43.  
  44.     class EnvData :
  45.        def __init__ (self , x , y, z ):
  46.                self . x = x
  47.                self . y = y
  48.                self.z=z
  49.  
  50.     def res():
  51.             obj_data = EnvData(x,y, z)
  52.             result = json.dumps(obj_data.__dict__)
  53.      
  54.             with open('dane.dat', 'w') as outfile:
  55.                 outfile.write(result)
  56.                 print(result)
  57.    
  58.    
  59.     sense.stick.direction_up = pushed_up
  60.     sense.stick.direction_down = pushed_down
  61.     sense.stick.direction_left = pushed_left
  62.     sense.stick.direction_right = pushed_right
  63.     sense.stick.direction_middle = pushed_middle
  64.     sense.stick.direction_any = res
  65.     res()
  66.    
  67.     selection = input("Press q to quit\n")
  68.     if selection is "Q" or selection is "q":
  69.         print ("Quitting")
  70.         sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement