Upload
anderson-anderson
View
215
Download
0
Tags:
Embed Size (px)
Citation preview
touchdevelop api
apiaccelerometermeasure acceleration
Disclaimer: This document is provided “as-is”. Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. You bear the risk of using it. This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and Windows Live are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners.
touchdevelop api
accelerometero electronic component that measures tilt and
motion• angle device is being held at
• movements such as rotation
• motion gestures such as swinging, shaking, and flicking
o detect whether the phone is held in “portrait” or “landscape” mode
o control games and other applications (such as music player) by moving or shaking the phone
touchdevelop api
3d coordinatesY is positive
when this edgeis “up” Z is negative
when this edgeis “up”
X is negativewhen this edgeis “up”
Y is negativewhen this edgeis “up”
Z is positivewhen this edgeis “up”
X is positivewhen this edgeis “up”
touchdevelop api
3d coordinateso length: o on Earth, when phone is steady,
direction changes depending on tilt
touchdevelop api
3d coordinates
Quiz: what is when…o phone is flat
on tableo you slightly
tilt ito phone stands
is upright
Y is positive when this edgeis “up” Z is negative
when this edgeis “up”
X is negativewhen this edgeis “up”
Y is negativewhen this edgeis “up”
Z is positivewhen this edgeis “up”
X is positivewhen this edgeis “up”
touchdevelop api
eventso shakeo phone face upo phone face downo phone portraito phone landscape lefto phone landscape right
touchdevelop api
apiso Senses→has accelerometer
Indicates whether accelerometer is present on device
touchdevelop api
apiso Senses→acceleration quick
Gets filtered accelerometer data using a combination of a low-pass and threshold triggered high-pass on each axis to eliminate the majority of the sensor low amplitude noise while trending very quickly to large offsets (not perfectly smooth signal in that case), providing a very low latency. This is ideal for quickly reacting UI updates.
o Senses→acceleration smoothGets filtered accelerometer data using a 1 Hz first-order low-pass on each axis to eliminate the main sensor noise while providing a medium latency. This can be used for moderately reacting UI updates requiring a very smooth signal.
o Senses→acceleration stableGets filtered and temporally averaged accelerometer data using an arithmetic mean of the last 25 'optimally filtered' samples, so over 500ms at 50Hz on each axis, to virtually eliminate most sensor noise. This provides a very stable reading but it has also a very high latency and cannot be used for rapidly reacting UI.
touchdevelop api
apiso Senses→is device stable
Indicates whether the device is 'stable' (no movement for about 0.5 seconds)
More precise when a gyroscope is also present:o Senses→motion
Gets the current phone motion that combines data from the accelerometer
o Motion→accelerationGets the linear acceleration of the device, in gravitational units.
touchdevelop api
exampleso accelerometer graph
☁ http://touchdevelop.com/anlc o accelero colors
☁ http://touchdevelop.com/wnny o bouncy balls
☁ http://touchdevelop.com/ojfl o turtle o meter
☁ http://touchdevelop.com/lkon o paddle game
☁ http://touchdevelop.com/awic
touchdevelop api
exercise►read accelerometer data:
action main while true do var p = senses→acceleration quick p→post to wall time→sleep(1)
o when running, tilt phone slowly in different wayso shake phone
touchdevelop api
exercises►map vector to background color
• use board
►bonus exercise: level• use just one axis
touchdevelop api
homework►finish exercises at home