Sample Programs

This program plays a continuous loop of attack robot phrases and sound effects. Press button P1.0 to begin playing. Press
P1.0 again to stop.

Download the program files: attack_robot_SFX.zip


HOOK-UP DIAGRAM

HOW THE PROGRAM WORKS

In the [device] section, we declare the SNC21030 device. There are only a few short audio files 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 and stop the audio and this button will be 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 three 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 "play_sfx" where the P1.0 input is set to "loop". This means that when the "play_sfx" state is set and pin P1.0 is triggered, the program will jump to the loop: label.
  • One state is called "stop_sfx" where the P1.0 input is set to "stop". This means that when the "stop_sfx" state is set and pin P1.0 is triggered, the program will jump to the stop: label.

In the [output_states] section, we do not define any outputs, since there are none (except the PWM speaker output).

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 "play_sfx", and then the end command puts the chip 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.

loop: The loop: path is called when the button is pressed. The first line in the loop: path sets 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.