HomeTurtlegraficsGPanelRobotics WebTigerPython |
Python - Online |
Deutsch English |
YOU LEARN HERE... |
how you can determine the magnetic field with the Calliope and how a gyro sensor works. |
DISPLAY SENSOR VALUES |
The magnetic field and gyro sensors are integrated in the hardware of the position sensor chip. The magnetic field sensor returns the current x, y and z components of the magnetic field at the location of the sensor. With magnatometer.get_x() you can query the x- components. With the Calliope mini3 you must use the compass.get_x() function.
|
EXAMPLES |
Search for mines
You use the function magnetometer.get_z(), which returns the strength of the magnetic field in the vertical plane. Then scale it so that you get a brightness value between 0 and 9. In the function light(v) you switch on all LEDs together. Program: from calliope_mini import * def light(n): for i in range(5): for k in range(5): display.set_pixel(i, k, n) while True: z = magnetometer.get_z() #z = compass.get_z() v = abs(z // 3300) n = min(9, v) light(n) sleep(20) Measuring the water level
Program: from calliope_mini import * import music state = "ok" while True: z = magnetometer.get_z() #z = compass.get_z() #print(z) if z >= 700 and state != "high": state = "high" print("->high") elif z >= 500 and z < 700 and state != "ok": state = "ok" print("->ok") elif z < 500 and state != "low": state = "low" print("->low") if state == "high": music.pitch(2000, 100) elif state == "low": music.pitch(500, 100) sleep(100) Note that the z-component of the magnetic field depends on the magnet you are using in this experiment. Activate the line print(z) at the beginning and change the limit values if necessary.
Program: from calliope_mini import * def light(n): for i in range(5): for k in range(5): display.set_pixel(i, k, n) while True: bz = gyrometer.get_z() v = abs(bz // 3300) v = min(9, v) light(v) sleep(20) |
REMEMBER ... |
The magnetic field sensor can be used for contactless detection of the position of a magnet or a magnetic coil. The gyro sensor is used to determine the speed of rotation. |
TO SOLVE BY YOURSELF |
|