C Language Development Kit/Functions/Sound

From OptiWiki

Jump to: navigation, search
Description This function sounds one tone or a sequence of tones.
Syntax
void sound(int time, int vol, ..., 0);
Arguments
int time
The parameter time defines the time of each tone, in steps of 20 milliseconds. For example, time = 50 is one second. The following constants are defined:
TCLICK Duration of 20 msec.
TSHORT Duration of 60 msec.
TSTANDARD Duration of 100 msec.
TLONG Duration of 200 msec.
TVLONG Duration of 400 msec.
int vol
The parameter vol specifies the volume. The following values are possible:
VOFF No volume at all.
VLOW Low volume.
VSTANDARD Standard volume.
VMEDIUM Medium volume.
VHIGH High volume.
..., 0
The last argument "... , 0" contains a sequence of at most 15 tones. The last tone should always be the value zero. Each tone can have one of the following values:
SERROR Very low error sound.
SLOW Low sound.
SMEDIUM Medium sound.
SHIGH High sound.
SPAUSE Pause of 100 msec.
Returns None
Remarks Program execution will continue while generating the sound sequence. If you want to execute sound() functions short after each other or want to wait until the sound is played, use the delay() function.

(On the OPH100x is also possible to use the function isBuzzerOn() to check whether the buzzer is still busy playing a previous sound or not.)

Example
#include "lib.h"
#include <stdio.h>
 
void main( void )
{
    while( 1 )
    {
        sound(TCLICK, VHIGH, SERROR, SPAUSE, SLOW, SPAUSE, SMEDIUM, SPAUSE, SHIGH,0);
        delay(200);   // Wait 4 sec
        sound(TSTANDARD, VHIGH, SERROR, SPAUSE, SLOW, SPAUSE, SMEDIUM, SPAUSE, SHIGH,0);
        delay(200);
        sound(TLONG, VHIGH, SERROR, SPAUSE, SLOW, SPAUSE, SMEDIUM, SPAUSE, SHIGH,0);
        delay(200);
        sound(TVLONG, VHIGH, SERROR, SPAUSE, SLOW, SPAUSE, SMEDIUM, SPAUSE, SHIGH, 0);
        delay(200);
    }
}


Views
Personal tools