# Micro:bit analog read is agonizingly slow?

**URL:** <https://forum.makecode.com/t/micro-bit-analog-read-is-agonizingly-slow/22028>\
**Category:** micro:bit\
**Created:** [August 24, 2023, 6:39am UTC](https://forum.makecode.com/t/micro-bit-analog-read-is-agonizingly-slow/22028 "2023-08-24T06:39:35Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![bsiever](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bsiever/32/1032_2.png) [@bsiever](https://forum.makecode.com/u/bsiever)\
**Post date:** [August 25, 2023, 3:02am UTC](https://forum.makecode.com/t/micro-bit-analog-read-is-agonizingly-slow/22028/3 "2023-08-25T03:02:59Z")

</div>

Hi @MCbubba77 ,

Since you mention a `forever` loop, I’m assuming you are working in MakeCode. MicroPython is probably different.

The `forever` loop has a 20ms pause built in on each iteration. There may be two reasons for this: 1) to allow other fibers to run to handle events, etc. and 2) to ensure the loop is slow enough to be noticeable to novice users (maybe). See [here](https://github.com/microsoft/pxt-microbit/blob/958401e2ee74e93848d6aae14d503bda72c0fba8/libs/core/codal.cpp#L128C9-L128C9) to see the actual loop. The period is at least 20ms, so the maximum on anything in a `forever` loop is 50Hz.

Here are some interesting examples/data from a V2:

- [Analog Read in a `forever` loop](https://makecode.microbit.org/S90197-45155-13842-63310): This was able to do about 50 cycles through the loop per second (50Hz), so the read itself is negligible in comparison to the 20mS sleep in the `forever` loop.
- [Analog Read in Tight Loop](https://makecode.microbit.org/S76489-64423-30500-99157): You can use a different style of infinite loop inTypeScript and omit the `pause` on each iteration. It was able to do about 29300 reads per second (and other logic). So a bit over 29kHz and maybe a little under 34.1 uS between reads. Of course, this may starve out other tasks.
- You can include a `pause(0)` in a tight loop to ensure other events are handled. That appears to significantly impact the period. It was able to do about 250Hz.

It looks like the `analog read` itself isn’t really slow. The `forever` is just throttled.

Bill

---

_[View the full topic](https://forum.makecode.com/t/micro-bit-analog-read-is-agonizingly-slow/22028)._
