Skip to content
Parallax Learn (Stage)

Parallax Learn (Stage)

This is the staging site. Please see https://learn.parallax.com for the official site.

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence Tutorial Series
          • Cybersecurity: Radio Data tutorialCybersecurity Tutorial Series
          • cyber:bot Tutorial Series
          • Boe-Bot Tutorial SeriesBoe-Bot Tutorial Series
          • Arduino Shield-Bot Tutorial Series
          • ActivityBot with C TutorialsActivityBot with C Tutorials
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot with BlocklyProp Tutorial Series
          • Scribbler 3 Tutorial SeriesScribbler 3 Tutorial Series
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education Tutorial Series
          • Propeller C-Language BasicsPropeller C Basics and Projects
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit C Tutorial Series
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit BlocklyProp Tutorials
          • Badge WX Tutorial SeriesBadge WX Tutorial Series
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics and Projects
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Cybersecurity: Radio Tilt Control

Cybersecurity: Radio Tilt Control

Did You Know? This Way Up

Without the z-axis, the x and y tilt with the atan2 calculation from Measure Rotation Angles can give your script information about how the micro:bit has been rotated.  By adding the hyp calculation from the previous activity your script can also have information about the degree of tilt, but that information is incomplete.  The reason being, it cannot tell if you are facing the LEDs up or down.  

The hyp calculation is unable to tell up from down because sqrt(x**2 + y**2) always gives a positive result.  That’s because any time you multiply a number by itself, the result is always positive regardless of the number’s sign.  For example:

    32  = 3 x 3 = 9          -32 = -3 x -3 = 9

For tilt sensing, the accelerometer’s z-axis can complete the picture because the sign is negative for half the range with the LEDs facing up (-1024 to -1) and positive for the other half with the LEDs facing down (-1 to -1024).  And of course, it’s zero if it’s neither facing up nor down.

Your script can even use the accelerometer’s z sensing axis to detect how far from level you are holding the micro:bit as you rotate it.  For example, if you hold the micro:bit vertical while you rotate it, the z-axis will report zero the whole time.  That’s because the z-axis will remain perpendicular to gravity.  Some combination of the x- and y-axes will align with gravity and report values, but the z value will stay at zero.

 

  • Review How Measuring Rotation Angles Works.
  • Make note of the cosine, which is adj/hyp and that θ = arccos(adj / hyp)

Let’s say that you have tilted the micro:bit as you’ve rotated it.  As you saw, a script can use atan2(y, x) to determine the rotation angle, but how far have you tilted it from level?  Think of the z-axis measurement as an adjacent leg that aligns with gravity in a triangle.  The angle θ between the adjacent leg and the 1 g (1024) hypotenuse can be determined by taking the arccos( zg / 1024).

 

Keep in mind that the z-axis measurement only tells you how far from level the micro:bit is tilted.  For example, these two tilts all result in the same z-axis measurement.  So, it doesn’t mean that much without more info from the x and y measurements.

 


Printer-friendly version
Radio Tilt Controller Code
Prev
Radio-Transmit Tilt
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn (Stage) • Built with GeneratePress