This program uses markers embedded into an audio file to automatically trigger events in the program. Press button P1.0 to play the audio file. As the audio file plays, the markers within the file trigger LEDs to turn on and off in time with the music.
Download the program files: event_marker_example.zip
HOW THE PROGRAM WORKS
In the [device] section, we declare the SNC21030 device. There is only one short audio file in this program, so we can use a small device.
In the [key] section, we set the number of direct inputs to 1. This program uses one button to start the audio and this button is connected to pin P1.0.
In the [files] section, we list the audio files that will be included as part of the program.
In the [input_states] section, we define two different input states.
- One state is called "locked_out" where the P1.0 input is set to "x". This means that when the "locked_out" input state is set, pin P1.0 will be ignored.
- One state is called "enabled" where the P1.0 input is set to "button1". This means that when the "enabled" state is set and pin P1.0 is triggered, the program will jump to the button1: label.
In the [output_states] section, we define the ON state for each of four LEDs. For example, in the program when we set the output state to led1_on, this outputs a high voltage on pin P3.0 and the LED connected to that pin turns on. This output state also sets the remaining P3 pins to zero, which turns off the other LEDs. The led2_on, led3_on, and led4_on output states have similar functions. The all_off output state can be used to set all P3 pins to zero, which turns off all four LEDs.
The [paths] section contains the various routines used in the program.
init: The "init" label always gets called first on power up and on reset. In this program, the init path sets the input state to "locked_out" so that the button is ignored. It then sets the sample playback rate to 12k, sets the input state to "enabled", and then the end command puts the chip into a low power state. Since the "enabled" state is the active input state, when the button is pressed the program will jump to the button1: label.
button1: The button1: path is called when the button is pressed. The first line in the button1: path enables the event markersets the input state to "stop_sfx". The loop: path then plays the various sound effects in the program in the order listed, along with some delay statements in between. At the end of the loop: path, the program jumps back to the loop: label so that the entire sequence is repeated. Since the "stop_sfx" state is the active input state, when the button is pressed the program will jump to the stop: label.
stop: The stop: path is called when the button is pressed again. The stop_v command immediately stops any audio that is playing, the input state is set to "play_sfx", and the end command puts the put into a low power state. Since the "play_sfx" state is the active input state, when the button is pressed the program will jump to the loop: label.