Accelerometer 

Accelerometers can be used to find the acceleration of a device. You can access this data from qdex using an accelerometer tag, then use it to control interactions and plots. Accelerations are output in units of metres per second squared.

The accelerometer data is stored inside of an inherent vector called value inside of the onValueChanged event. As with simulations, qdex will not start to read accelerometer data until the accelerometer is started using the Start() method, or signalled from a simulation. 

 
acceleromter-orientation.jpg
 
phone-x-axis.jpg

value[1]
Movement along the x-axis

phone-y-axis.jpg

value[2]
Movement along the y-axis

phone-z-axis.jpg

value[3]
Movement along the z-axis

In the example below, the accelerometer data is output to a label, and used to change the angle of a line on a plot. The accelerometer begins to read data when the page is active

<script>
  local x,y;
  local h = 10;
  local myLine = thisPlot.plotLine;
</script>

<accelerometer name="myAccel">
  <onActivePageChanged>
    if active then
    myAccel:Start()
    else
    myAccel:Stop()
    end
  </onActivePageChanged> 
  <onValueChanged>
    myLabel.Text = string.format("%d %d %d", value[1], value[2], value[3])
    
    y = value[1]
    x = math.sqrt(h*h - y*y)
    myLine:Add(0,0)
    myLine:Add(x,y)
    myLine:Update()        
  </onValueChanged>
</accelerometer>

<label name="myLabel" />

<xyPlot name="thisPlot">
  <axis dim="x" auto="fixed" min="0" max="11" />
  <axis dim="y" auto="lockAspectRatio" />
  <series name="plotLine" manual="true" capacity="2" />
</xyPlot>