Derik Whittaker

Syndication

News


How to use the Inclinometer sensor in Windows 8 C#/XAML applications

This post is part of a mulit-part posting series on how to use some of the onboard device sensors in Windows 8 applications.  Other posts are:

Most tablets and laptops these days have an array of sensors onboard the device that developers can use and take advantage of. One of the sensors which is on most tables and laptops is the Inclinometer Sensor.  The Inclinometer is a sensor which allows you to measure the movement of the device in terms of Pitch, Roll and Yaw, or more simply rotation of the device on the X, Y and Z axis.  With the Inclinometer you could build interesting augmented reality applications which react to the movement of the device.  In this post we are going to take a look at how to use the inclinometer Sensor from within your C#/XAML Windows 8 application.

How to get access to the Inclinometer

In the above code what we are doing is making the call to get the Default sensor, this is the sensor on the device.  If there is NO sensor on the users device it will return a NULL instance which is why we are checking for null.  Make sure you do the same in your code

Register to receive event updates when the Inclinometer values change

In the above I am either registering for an event or unregistering.  The event is what will give us the updated values as they change based on the movement of the users device.

Doing something useful with the sensor readings

In the above I am doing 2 things of note:

  1. I am using a CoreDispatcher (you can get this from Window.Current.Dispatcher) in order to message the results back onto the UI thread.  If you do not need to message back to the UI thread you will NOT need this
  2. I am getting the current reading for each axis via the .Reading property of the event argument.  It is here you could do something useful with the reading.

As you can see working with the Inclinometer sensor is not too hard and can lead to some pretty useful features in your application.

Till next time,


Posted 01-23-2013 7:02 AM by Derik Whittaker
Filed under: , , ,

[Advertisement]

Comments

Derik Whittaker wrote How to use the Accelerometer in Windows 8 C#/XAML Applications
on 01-27-2013 3:15 PM

This post is part of a mulit-part posting series on how to use some of the onboard device sensors in

bookmarks wrote re: How to use the Inclinometer sensor in Windows 8 C#/XAML applications
on 03-15-2013 7:59 AM

peThE5 Great, thanks for sharing this blog article.Really thank you!

Social bookmarks wrote re: How to use the Inclinometer sensor in Windows 8 C#/XAML applications
on 03-22-2013 10:49 PM

IvBk8X Thanks for the post.Thanks Again.

Social bookmarks wrote re: How to use the Inclinometer sensor in Windows 8 C#/XAML applications
on 03-24-2013 9:35 PM

KPcGbV Thanks-a-mundo for the blog post. Much obliged.

Social bookmarks wrote re: How to use the Inclinometer sensor in Windows 8 C#/XAML applications
on 04-03-2013 8:39 PM

6VfyN4 Really informative blog.Thanks Again.

social bookmarking service wrote re: How to use the Inclinometer sensor in Windows 8 C#/XAML applications
on 04-03-2013 11:55 PM

NqjSNU I cannot thank you enough for the article.Much thanks again. Awesome.

stoner wrote re: How to use the Inclinometer sensor in Windows 8 C#/XAML applications
on 04-05-2013 10:54 PM

Awesome blog article.Really thank you! Cool.

comedy shirts wrote re: How to use the Inclinometer sensor in Windows 8 C#/XAML applications
on 04-06-2013 12:57 AM

Fantastic article post.Really looking forward to read more. Cool.

social bookmarking service wrote re: How to use the Inclinometer sensor in Windows 8 C#/XAML applications
on 04-08-2013 5:16 AM

co1oQo This is one awesome blog article.Much thanks again. Want more.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)