For information about how to run the program, please visit the COMP2300 course website.
An engaging musical light show on the BBC micro:bit v2 (ANU COMP2300 assignment).
We develop an ARM Assembly program that produces a two-part light show with sound on micro:bit.
- Pt.1
- Light
- Small dots move over the board and transform into a crosshair.
- Crosshair aims around and expands into spurts, transforming into a windmill.
- The windmill spins clockwise and then anti-clockwise, ends as a beating heart.
- Sound
- Matching the blink of lights, James Bond Theme is played.
- Light
- Pt.2
- Light
- The Matrix-style falling strips replace the Bond-style blood drip scene.
- Stripe lengths are generated randomly to make the light show ever-changing.
- Sound
- A specific byte beat music is played continuously.
- Light
An LED can be enlightened by changing the value of its corresponding pins for the row and the column using the load-twiddle-store pattern [1].
-
Pt.1 music consists of various music notes with durations, and each music note corresponds to a specific frequency value [2]. Such frequency values can be used with constant positive/negative amplitude values to produce audible square waves as music.
-
Pt.2 byte beat music derives from arithmetic operations with an incrementing number in an infinite loop [3]. Essentially, it produces an audible sawtooth wave as music.
- There is no built-in function for a random number generator in ARM Assembly.
- The RNG peripheral on the micro:bit is constrained in a range of 0-255.
The goal can still be achieved using the linear congruential generator (LCG); the equation is as below [4]
Note that the result value generated by LCG is deterministic if the seed is defined.
We first produce a random value using RNG and then seed that value to LCG to create a truly random number that is not constrained to RNG's range.
src
┣ main.S
┣ music.S
┣ part-1.S
┣ part-2.S
┗ rand.S
The main
function first initialises the micro:bit audio function by calling audio_init
, then plays Pt.1 and Pt.2 of the light show in sequence by calling Pt_1
and Pt_2
.
- In
Pt_1
, we pass the input data from memory toframe_n_music
, where we scan an LED matrix column by column repeatedly and enlighten the rows that should be on by calling a set ofset/clear-DIR/OUT
functions. The duration of this process is adjusted roughly the same as the current music note duration. When it ends, we play the current music note by callingmusic_note
. - In
Pt_2
, we callgenerate_next_frame
to generate the next frame of an image by shifting down the current frame and leaving the header row to randomness. Hence, when we callframe_n_bytebeat
, the strips are random in length and look like falling, while exciting byte beat music is played.
Our program imitates classic movies to implement an ever-changing light show with exciting sound effects and some randomness on the micro:bit, which lives up to our goal of an engaging light show.
- We use highly modularised functions with high cohesion and low coupling; hence, they are easy to modify and understand.
- The LED status matrix and music frequency-duration table data are all stored in the
.data
section on memory, which saves lots of register usage.
- When playing music notes in Pt.1, LED lights are cut off. This can be improved by merging the loops for both light and sound.
- Although the falling strips in Pt.2 are generative, the byte beat is always in the same loop. The sound can be randomised too.
[1]"Week 4: blinky", Computer Organisation and Program Execution, 2022. [Online]. Available: https://comp.anu.edu.au/courses/comp2300/labs/04-blinky/. [Accessed: 03- Apr- 2022].
[2]"Frequencies of Musical Notes, A4 = 440 Hz", Pages.mtu.edu, 2022. [Online]. Available: https://pages.mtu.edu/~suits/notefreqs.html. [Accessed: 03- Apr- 2022].
[3]V. Heikkilä, "Discovering novel computer music techniques by exploring the space of short computer programs", arXiv, 2011. Available: https://arxiv.org/abs/1112.1368. [Accessed 3 April 2022].
[4]"Linear congruential generator - Wikipedia", En.wikipedia.org, 2022. [Online]. Available: https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use. [Accessed: 03- Apr- 2022].