Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import json
- import sys
- import getopt
- import linecache
- from sense_emu import SenseHat, ACTION_PRESSED, ACTION_HELD, ACTION_RELEASED
- from signal import pause
- x = 0
- y = 0
- z = 0
- sense = SenseHat()
- while True:
- def pushed_up(event):
- global y
- if event.action != ACTION_RELEASED:
- y = y + 1
- def pushed_down(event):
- global y
- if event.action != ACTION_RELEASED:
- y = y - 1
- def pushed_left(event):
- global x
- if event.action != ACTION_RELEASED:
- x = x - 1
- def pushed_right(event):
- global x
- if event.action != ACTION_RELEASED:
- x = x + 1
- def pushed_middle(event):
- global z
- if event.action != ACTION_RELEASED:
- z = z + 1
- class EnvData :
- def __init__ (self , x , y, z ):
- self . x = x
- self . y = y
- self.z=z
- def res():
- obj_data = EnvData(x,y, z)
- result = json.dumps(obj_data.__dict__)
- with open('dane.dat', 'w') as outfile:
- outfile.write(result)
- print(result)
- sense.stick.direction_up = pushed_up
- sense.stick.direction_down = pushed_down
- sense.stick.direction_left = pushed_left
- sense.stick.direction_right = pushed_right
- sense.stick.direction_middle = pushed_middle
- sense.stick.direction_any = res
- res()
- selection = input("Press q to quit\n")
- if selection is "Q" or selection is "q":
- print ("Quitting")
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement