2016-10-27 15:51:42 +02:00
|
|
|
#include "ksbit.h"
|
|
|
|
|
|
|
|
namespace music {
|
2016-10-27 17:44:38 +02:00
|
|
|
/**
|
|
|
|
* Plays a tone through ``speaker`` for the given duration.
|
|
|
|
* @param frequency pitch of the tone to play in Hertz (Hz)
|
|
|
|
* @param ms tone duration in milliseconds (ms)
|
|
|
|
*/
|
|
|
|
//% help=music/play-tone weight=90
|
|
|
|
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8
|
2016-11-16 07:28:05 +01:00
|
|
|
//% parts="speaker" async
|
2016-10-27 15:51:42 +02:00
|
|
|
void playTone(int freqency, int ms) {
|
2016-10-27 17:44:38 +02:00
|
|
|
uBit.soundmotor.soundOn(freqency);
|
2016-10-27 15:51:42 +02:00
|
|
|
if(ms > 0) uBit.sleep(ms);
|
2016-10-27 17:44:38 +02:00
|
|
|
uBit.soundmotor.soundOff();
|
2016-10-27 15:51:42 +02:00
|
|
|
}
|
|
|
|
}
|