Frequencies of musical notes and tempo are all wrong when played on a micro.bit

I received the latest V2 micro.bit yesterday and the simple tutorial exercises work well, except selecting notes like Middle C from “Music” followed by Middle G does not play as the notes and is not in harmony. Also the temp setting seems to be all wrong. Below is the full program I copied from a website Behind the MakeCode Hardware - Speaker on the Circuit Playground Express. The tune played is supposed to be “Mary Had a Little Lamb”

on start
    set volume (200)
    change tempo by (bpm) (60)

on button (A) pressed
   play (tone (Middle C) for 1/4 beat) until done
    rest for (1/8 beat)
   play (tone (Middle C) for 1/4 beat) until done
    rest for (1/8 beat)
   play (tone (Middle G) for 1/4 beat) until done
    rest for (1/8 beat)
   play (tone (Middle G) for 1/4 beat) until done
    rest for (1/8 beat)
   play (tone (Middle A) for 1/4 beat) until done
    rest for (1/8 beat)
   play (tone (Middle A) for 1/4 beat) until done
    rest for (1/8 beat)
   play (tone (Middle G) for 1/2 beat) until done
    rest for (1/8 beat)

I do not understand what “until done” does"? the original code did not have it, but I don not seem to be able to select “Block Code” without that extension.

Any Help would be appreciated.

I am a retired Software Engineer, who has developed the language immdiate C, an “Event Driven” extension of the C language - suitable for Machine Control, Internet of Things (IOT), GUi’s and Games.
Since micro.bit supports both SPI and I2C, I want to use micro.bit as a simple I/O device. I have drivers for both SPI and I2C for immediate C.

Hi @Roo,

I can’t speak to your questions on tempo or tone. You may want to look at the source code for music.ts, music.cpp, and playable.ts.

I can give some direction on until done — it just means that it’s blocking within that scope. When programming in the “code blocks”, one usually wants blocking (until done) behavior for notes so they can hear each note for an appropriate duration. If non-blocking you’d only hear the last note… On the other hand, sometimes you want to play a sound nearly forever. Here’s an example that you can pick the three options via the dropdown in the play block and get a sense of the differences in behavior: https://makecode.microbit.org/S83895-76743-27699-85070 (Clicking A in the simulator and seeing the images on screen and tone durations).

There are maybe two different reasons for the difference in the block in Circuit Express: 1) It may have been an intentional choice to keep it simpler for Circuit Express (no background option) or, in my opinion the more likely reason, 2) they just based it on an older version of MakeCode before background music was supported. You’re using play on the micro:bit currently includes a PlaybackMode option, but the history of the API only goes back to 2023. MakeCode for the micro:bit still includes a simple playTone(), but it’s deprecated. The playTone you see in CircuitExpress appears to be based on the older MakeCode API.

You can access SPI and I2C from the MakeCode level APIs (TypeScript, Python, blocks), but sometimes it’s easier to do hardware from a C++ extension.

Hope that helps a bit!