Using knock codes to adjust settings on the MP3 player

Skip to main content (skip navigation menu)
Letterhead logo

Using "knock codes" to adjust settings on an "in-service" system


In this article, I am using our programmable MP3 player as an example for a concrete implementation. The principle (or "trick") applies to other programmable logic too. That behind us, let me proceed.

The H0420 programmable MP3 player is often used inside game consoles, kiosks or scale models ("maquettes"), where they are activated through (vandal-resistant) switches or (hidden) sensors. A frequent request from the shop owner or site manager is that employees are able to adjust settings of the device —without needing a screwdriver. Especially the personnel wants to be able to adjust the audio volume to be in balance with the level of environmental noise, which changes from day to day: volume up on a busy (read "noisy") day and volume down on a quiet day.

If this desire for easy adjustment is considered from the start of the design of the console, the kiosk or the scale model, typical solutions are a hidden switch, a key-lock switch, centralized control via the X-10 protocol (with an X-10 "appliance module" connected to a programmable switch input of the H0420 MP3 player), or remote control (e.g. with an IR-receiver chip branched onto a digital I/O line of the H0420).

In practice, though, configurability of the device often comes as an aferthought: when the game console, the kiosk or the scale model has already been built and installed; when adding switches or peripherals has become impractical...

Enter knock codes

Assuming that there is at least one "push-button" switch or sensor connected to the H0420 (on either a switch input or an I/O pin), you can use it to enter a secret "knock code". Upon reception of the knock code, the program/script for the H0420 enters the "adjust-settings" mode. In this mode, the standard switch(es) or sensor(s) modify the settings of the device (e.g. the volume level). If you do not activate a switch or sensor for a while, the system stores the new settings and resumes normal mode.

A knock code is a series of digits, separated by pauses of approximately one second. Each digit is a series of "knocks": short button presses or sensor activations. The pauses between two knocks should be well below the one second that separates the digits of the code. Digits often range from 1 to 5, because longer sequences get harder to "knock in" without concious counting, and a complete knock code should be entered without hesitation. The number of digits in a code depends on the level of security that you wish; four or five digits is typical.

If a red dot in the figure below stands for the detection of a button press, and the green line is the time-line (with markers for seconds), the figure represents the knock code 3-1-5-2.

Graph of a knock code on a timeline

Depending on the method of entering the knock code, including the type of button or sensors suitable for the task, the criterion for the duration of a pause that separates the digits may need to be adjusted. In the previous explanation, this was set to one second, but for slow sensors, you may need to increase it. In addition to a criterion that indicates a new digit in the code, you also need a criterion to mark the end of the code. A good value is twice the duration of a pause between digits, or two seconds in general.

Detecting knock codes

Detecting a knock code is a matter of detecting input (switches or I/O pins) and acquiring time stamps. That, plus counting and matching. It is not difficult at all, but it requires some amount of code. Below is a routine that detects a knock code, based on a switch press (it assumes there is a push-button connected to switch input 0). You would call this function from @button() and if it returns true, do something special.


To get you started, below are a few files that you can download and runs as is, or modify for your purposes.

Further reading & references

H0420 Programmable MP3 Player
The main page for the MP3 player that this article applies to.
the pawn programming language
The page describing the scripting language used on the H0420 MP3 player, including manuals and downloads.
A remote-controlled MP3 player
An alternative way to change settings on a "live" system is to connect a tiny IR-receiver chip to the H0420 and use a common remote control. This page has all the details.