Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __version__ = '1.0' # declare the app version. Will be used by buildozer
- import time
- from kivy.app import App # for the main app
- from kivy.uix.floatlayout import FloatLayout # the UI layout
- from kivy.uix.label import Label # a label to show information
- from plyer import accelerometer # object to read the accelerometer
- from plyer import gyroscope
- from plyer import gps
- from plyer import temperature
- from plyer import compass
- from kivy.clock import Clock # clock to schedule a method
- class UI(FloatLayout): # the app ui
- def __init__(self, **kwargs):
- super(UI, self).__init__(**kwargs)
- self.lblAcce = Label(text="Датчики")
- self.add_widget(self.lblAcce)
- try:
- accelerometer.enable()
- gyroscope.enable()
- compass.enable()
- Clock.schedule_interval(self.update, 1.0 / 60) # 60 вызовов в секунду
- except:
- self.lblAcce.text = "Перезапустите приложение"
- def update(self, dt):
- txt = ""
- try:
- accel = accelerometer.acceleration
- gyro = gyroscope.rotation
- gps = compass.field
- txt = "Акселерометр:\nX = %.2f\nY = %.2f\nZ = %2.f " % (
- accel[0], # read the X value
- accel[1], # Y
- accel[2]) + \
- "\n\nГироскоп:\nX = %.2f\nY = %.2f\nZ = %2.f " % (
- gyro[0],
- gyro[1],
- gyro[2]) + \
- "\n\nКомпасс: \nX = %.2f\nY = %.2f\nZ = %2.f " % (
- gps[0],
- gps[1],
- gps[2])
- except:
- txt = "Перезапустите приложение" # error
- self.lblAcce.text = txt # add the correct text
- class Sensors(App): # our app
- def build(self):
- ui = UI() # create the UI
- return ui # show it
- if __name__ == '__main__':
- Sensors().run() # start our app
Add Comment
Please, Sign In to add comment