TigerJython4Kids | robotics |
deutsch english |
YOU LEARN HERE... |
how to use the micro:bit to monitor systems and trigger an alarm if necessary. |
MONITORING WATER LEVEL |
|
|
Program: from microbit import * while True: v = pin0.read_analog() print(v) sleep(500) Complete your system with a visual alarm indicator on the LED display. |
SIMPLE TRANSISTOR AMPLIFIER |
|
MEMO |
You can easily set up simple alarm systems with the micro:bit as an embedded system, if you combine your manual skills with some electronics and programming knowledge. |
EXERCISES |
|
Acceleration generally means the rate of change of velocity, that is, one-dimensional
where v is the speed.
From the three acceleration components you can calculate pitch and roll angles as shown below. Start the following program and tilt the board sideways or forwards and backwards. In the terminal window, the values of pitch and roll are written out in degrees.
from microbit import * from math import * def getPitch(): a = accelerometer.get_values() pitch = atan2(a[1], -a[2]) return int(degrees(pitch)) def getRoll(): a = accelerometer.get_values() anorm = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]) roll = asin(a[0] / anorm) return int(degrees(roll)) while True: pitch = getPitch() roll = getRoll() print("p: " + str(pitch)) print("r: " + str(roll)) print() sleep(100)