Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

With the following code I can get the value of the "Sudden Motion Sensor", which is build into MacBooks:

Dynamic@ControllerState[{"X", "Y", "Z"}, ControllerPath -> {"Sudden Motion Sensor"}]

I want to use the values to control some variables in a Manipulate statement, however this doesn't seems to work:

Manipulate[x,"X" -> {x, -1, 1}, ControllerPath -> "Sudden Motion Sensor"]
share|improve this question
    
off topic but do you know which apple laptops have SMS? a macbook I had did have an SMS, my current air does not seem to have one (or at least I cannot see any indication via pmset, mathematica does not find it etc). this despite not finding any info anywhere about it not being included in SSD notebooks. –  acl Feb 20 '13 at 20:08
    
@acl It would only make sense to have in MacBooks with a HDD for its original purpose, but i don't know. –  Tyilo Feb 20 '13 at 20:13
1  
@acl Here it is: support.apple.com/kb/HT1935, only HDD MacBooks have it. –  Tyilo Feb 20 '13 at 20:14
    
Thanks, I read "All Intel-based Mac notebooks have Sudden Motion Sensor technology" and somehow skipped over "Computers with Solid State Drives (SSD) or Flash Storage do not use SMS"... –  acl Feb 20 '13 at 20:15

1 Answer 1

up vote 4 down vote accepted

One can set variables equal to the controller values like below. They can then be used in a computation. Here I just scaled them by a.

Manipulate[
 {x0, y0, z0} = ControllerState[{"X", "Y", "Z"}, ControllerPath -> {"Sudden Motion Sensor"}];
 a {x0, y0, z0},
 {a, 1, 100}
 ]

Controlling the view point of 3D graphics could be fun, except that it's rather shaky on my computer. Here the ViewVector is determined by the controller values, and a changes the plot:

Manipulate[
 Plot3D[x^2 + a y^2, {x, -1, 1}, {y, -1, 1}, 
  ViewVector -> Dynamic[{-5 Normalize@ControllerState[{"X", "Y", "Z"}, 
        ControllerPath -> {"Sudden Motion Sensor"}], {0, 0, 0.5 + a/2}}],
  SphericalRegion -> True],
 {a, 0.5, 2}
 ]

But I find my SMS rather noisy and in need of smoothing. Also my "Y" coordinate seems to take on only two values, plus or minus 0.0039.


Or perhaps one would like to see a slider:

Manipulate[
 x,
 {x, -1, 1,
    Slider[Dynamic[x, x = ControllerState["X", ControllerPath -> {"Sudden Motion Sensor"}]], {-1, 1}] &}
 ]

However, the Dynamic inside Slider overrides the usual action of the Slider. It basically just displays its position according to the sensor's x value.

share|improve this answer
    
That doesn't directly modify a. Isn't it possible to do that? –  Tyilo Feb 20 '13 at 20:55
    
@Tyllo Do you want a set equal to one of the SMS coordinates, or some function of them? –  Michael E2 Feb 20 '13 at 20:56
    
Nevermind, it works perfectly. –  Tyilo Feb 20 '13 at 21:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.