How the Decimal Code Works
Node How it Works: decimal_pin_pad_transmitter
Compared to the first binary pin_pad_transmitter project, this decimal version has the same statements, up through set x to length of (pin).
When button A is pressed to select the next digit, the project remembers that digit by increasing the value of n. It also represents 0 with no lights, 1 with the row 0 LED on, 2 with the row 1 LED on, and so on, up through 5 with the row 4 LED on. The if (n < 5) block takes care of adding 1 to n and successively turning on each LED in the column. If all the lights are on and you press A again, the else block takes care of setting n to 0 and turning off all the lights.
Take a close look at if (n ≠ 0) above. It prevents any lights from turning on when n is 0. When n is 1, it has to turn on the light in row 0. Since the row with the light on has an index of one below the value of n, set y to (n – 1) stores the value of the correct row index in y to turn on the correct LED.
When button B is pressed, the project has to update the pin string and reset n to 0 so that you can enter the next column. If button B is pressed to enter a digit in the third column, it also has to send the pin string to the decimal vault micro:bit.
In set pin to (join (pin) (convert (n) to text)), the (convert (n) to text) call returns a string with a single digit character that represents the value n stores. That character could be ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, or ‘5’. The set pin to part appends that character to the pin string. When the pin string is appended with the third digit, length of (pin) will return 3. At that point, the if (length of (pin) = 3) block sends the pin string to the Vault Receiver micro:bit, scrolls the digits across the LED display, resets pin to an empty string, and clears the display.
How it Works: decimal_bank_vault_receiver
Aside from the comment with the project’s name, only few other blocks were changed. In the original binary version, the project initialized pin to ‘011’, then displayed a dot in the center of the LED display.
In the decimal version, all that really needed to change was the pin string—from ‘011’ to ‘324’. Since there might be some confusion about whether the original binary or updated decimal version of the vault receiver project is running, the single pixel in the center of the binary version was changed to a small square in the center of the decimal version.