Accelerometer and gyroscope, accelerometer Gyroscope

Source: Internet
Author: User

Accelerometer and gyroscope, accelerometer Gyroscope

If an instance of the motion manager needs to be created in the program, an instance should provide the accelerator and gyroscope motion services to the whole program. because the device only has one accelerator and one gyroscope, the use of Singleton is more logical.

The framework used to create the motion manager is CoreMotion. framework.

Introduce the header file # import <CoreMotion/CoreMotion. h>

// Initialize the motion manager CMMotionManager * motionManager = [[CMMotionManager alloc] init]; // determines whether the device supports the accelerator and gyroscope if (motionManager. accelerometerAvailable & motionManager. gyroAvailable) {// set the time for the accelerator to send an update motionManager every 0.01 seconds. accelerometerUpdateInterval =. 01; // receives the gyroscope motionManager. gyroUpdateInterval =. 01; // start the accelerator count update and specify the execution block for each accelerator count update [motionManager resume: [NSOperationQueue currentQueue] withHandler: ^ (CMAccelerometerData * accelerometerData, NSError * error) {// code block}]; [motionManager startGyroUpdatesToQueue: [NSOperationQueue currentQueue] withHandler: ^ (CMGyroData * gyroData, NSError * error) {// code block}];} else {NSLog (@ "the device does not support gyroscope ");}

If you want to stop receiving updates to the accelerometer and gyroscope
[MotionManager stopAccelerometerUpdates];
[MotionManager stopGyroUpdates];

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.