Skip to content
Parallax Learn

Parallax Learn

  • 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
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • 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
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Cybersecurity: Radio Tilt Control

Cybersecurity: Radio Tilt Control

How It Works

The first portion of the code is the same as the project test_accel_xy_angle from the previous activity.

Here is the one block that was added that calculates a number that can be used to indicate the degree of tilt. It calculates x2 + y2, and then takes the square root of that. What it’s calculating is the length of the hypotenuse of the triangles introduced in the previous Did You Know? page on trigonometry. More details are in the next Did You Know? section below.

A serial write statement was added to show the hypotenuse (hyp) result on another line.

Did You Know?

As you’ve seen with the rotate_angle_with_degree_of_tilt project, the micro:bit can report tilt level along with rotation. But is there really a relationship between the rotation angle and the level of tilt? 

The answer is yes. Just as the x-axis measurement is the adjacent leg of the triangle and the y-axis is the opposite leg, the tilt away from vertical is indicated by the hypotenuse. 

Here’s an example where the hypotenuse is calculated with the 30° values of xg = 888 and yg = 512. The result is 1025, which is essentially a total of 1g, meaning that the micro:bit is being held vertical.

Here is another example where the hypotenuse is calculated with the rotation of 45°, and tilted away at 45°. For this, the values of xg = 512 and yg = 512. The result is 724. The closer the tilt gets to level, the smaller the hypotenuse value will be.

You might encounter this calculation described as a vector magnitude in later physics and engineering classes.


Printer-friendly version
Measure How Far from Vertical or Level
Prev
Z-Axis: Which Way Is Up?
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress