How can I read the value of the BBC micro:bit's infrared (IR) and magnetometer sensors in JavaScript and microPyhon?
Seems that in Javascript let irValue = input.temperature() uses he IR sensor to provide temperature in Celsius instead of infrared light intensity.
And let heading = input.compassHeading() presents a text message asking to to tilt the microbit vs. providing the heading angle.
The microbit has no in board IR sensor. It has a temperature sensor which is actually the core temperature sensor in the MCU. It can be used to at best estimate ambient temperature, since to a variable extent it will be influenced by how hard the core is working and self-heating. The documentation is clear on that:
The fact that you have found code that misleadingly assigns the temperature sensor output to a variable that implies it is measureing IR intensity does not make it true.
You could use an IR photo-diode to measure IR intensity via one if the available analogue input pins. Be aware that many external IR sensors are intended for IR remote control and data and are digital in nature, not analogue. They detect a modulated IR signal as binary (on/off) states not intensity.
With respect to the magnetometer, it is a three axis device, and some math and calibration is required to get a compass heading.
input.compassHeading()is part of a higher level API that performs that math. The documentation includes:Which is what you are seeing in first-time use of the compass. You can run the calibration separately if you want to do that before actually reading the compass.
input.calibrateCompass().