Candleabra Microbit controller.

on start

Variable initialisation
Set the BLE group, paired is a boolean that is set true if BLE is active
Fore and Back are used in the stepping function for setting foreground and background colours.
Offset1, Offset2 and Mode and used in function pairs.
List is a array of colours values for Red (16711680), Green (65280) and Blue (255).
Inc is the pattern counter.
Initialise 4 RGB Neopixels using port P0 and set to off.

forever

Pattern types 16 to 26 
radio_tx

Sends the selected pattern letter to the remote control if BLE is active.

press_A

Function called when button A is pressed.
This increments the pattern number by +1, If the pattern number is >26 it is reset to 0.
This pattern number is offset by 64 and converted to the equivalent ASCII character from A to Z and then shown on the display.
Function radio_tx is called to send, the ASCII character code to the remote controller.
If pattern number is <16 then call the function sequence which executes singles if the pattern number is <=3 else executes pairings if pattern number is >=4 and <=15

press_B

Function called when button B is pressed.
This decrements the pattern number by -1, If the pattern number is <1 it is reset to 27.
This pattern number is offset by 64 and converted to the equivalent ASCII character from A to Z and then shown on the display.
Function radio_tx is called to send, the ASCII character code to the remote controller.
If pattern number is <16 then call the function sequence which executes singles if the pattern number is <=3 else executes pairings if pattern number is >=4 and <=15.
press_AB

Function called when button A+B is pressed.
This resets the pattern number to 0.
This pattern number is converted to the equivalent ASCII character and then shown on the display.
Function radio_tx is called to send, the ASCII character code to the remote controller.
The Neopixel string is then switched off.

on_button

The on button events that call the appropriate function.

On radio received number

If BLE is active and paired is true then the appropriate function is called for the equivalent button press on the remote control.
Therefore, the button presses on the remote controller behave exactly the same way as the buttons on the receiver.

on radio received name value

This event verifies the name sent by the remote controller which if it matches sets paired to true.
This then enables the transmission of the pattern number to remote controller to display the pattern selected.

radio_tx

Transmits the pattern number to the remote controller as the ASCII code if paired is true.

sequence

Calls the appropriate function based on the pattern number.
If pattern number is <16 then call the function sequence which executes singles if the pattern number is <=3 else executes pairings if pattern number is >=4 and <=15.

reset

Called to set the RGB variables to 0 which are then used to switch of the Neopixel string.

lrfade

Function lrfade performs a rainbow fade across the Neopixel string from the left then the right.

stepping

The function steps a foreground colour through the Neopixel string set to a background colour.
The whole string is set to the background colour then each pixel is lit in turn in the foreground colour while the previous pixel is lit in the background colour.

rud

Function rud sets a colour in pixel pairs.
Pixel pairs 0 & 3 are positive offset and pairs 1 & 2 and negative offset.
The offsets from the reference determine the colour.

randomit

Function randomit sets a random colour within the range 0 to 16711680 on each pixel independently from each other.

rainbow2

Function raindow2 applies a rainbow pattern across the string within a random range of 0 to 16711680.
randoms

Function randoms applies a random colour in the range 0 to 16711680 on random pixels.

singles

Function singles sets all the string to a single colour (R, G or B), the colour being dependant upon the inc value.

pairings

Function pairings is used in conjunction with function pairs to set specific colours on specific pixel pair combinations.

pairs

Function pairs sets pixel pair colours based on the offset applied to the list array which determines the colour value assigned.