Search code examples
androidorientationsensorsapp-inventor

Event driven alarm with roll and pitch in App Inventor 2


I'm currently trying to learn the AppInventor2 tool, by coding a roll and pitch application similar to the one listed in app Inventor gallery (Balance Meter).

What I want to do, is enhancing the rolling from the OrientationSensor, by triggering a sound on certain values reached.

So far I know that the rolling is marked from -90 to 90 degrees. Although I have declared a lower value e.g. 30 to 35 degrees, I get the sound triggered only on the leftwards rolling of the device, but not on the other side. I want it to be triggered when rolling occur form e.g. -30 to 35 degrees respectively.

The following image shows the blocks I've used:

enter image description here

Need to mention that orientation of app is in landscape mode only, with home button on right side.

Could anyone be kind enough to give me a clue to the right blocks to use, or to the logic I should be followed to make this work? Thank you all in advance for your answers.


Solution

  • instead of the random integer block just use an or block to play sound if roll > 30 or roll < -30

    enter image description here

    or if you only want to play the sound if roll is between -35 and -30 or between 30 and 35

    enter image description here