3.9.2.3 class AccelerometerXYZAxisData

Class Attributes

Example

from sensor import *
import e32
import time

class DemoApp():
    def __init__(self):
        self.accelerometer = \
            AccelerometerXYZAxisData(data_filter=LowPassFilter())
        self.accelerometer.set_callback(data_callback=self.my_callback)
        self.counter = 0

    def my_callback(self):
        # For stream sensor data the callback is hit 35 times per sec(On
        # 5800). The device cannot handle resource hungry operations like
        # print in the callback function for such high frequencies. A
        # workaround is to sample the data as demonstrated below.

        if self.counter % 5 == 0:
            print  "X:%s, Y:%s, Z:%s" % (self.accelerometer.x, self.accelerometer.y,  self.accelerometer.z)
        self.counter = self.counter + 1

    def run(self):
        self.accelerometer.start_listening()

if __name__ == '__main__':
    d = DemoApp()
    d.run()
    e32.ao_sleep(1)
    d.accelerometer.stop_listening()
    print "Exiting Accelorometer"

See About this document... for information on suggesting changes.