pxt-calliope/libs/core/music.cpp

29 lines
939 B
C++
Raw Normal View History

2016-10-27 19:48:42 +02:00
#include "ksbit.h"
namespace music {
/**
* 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-10-27 22:47:39 +02:00
//% parts="speaker" async
2016-11-03 16:50:02 +01:00
void playTone(int frequency, int ms) {
uBit.soundmotor.Sound_On(frequency);
2016-10-27 19:48:42 +02:00
if(ms > 0) uBit.sleep(ms);
uBit.soundmotor.Sound_Off();
}
/**
* Plays a tone through ``speaker``.
* @param frequency pitch of the tone to play in Hertz (Hz)
*/
//% help=music/ring-tone weight=80
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" icon="\uf025" blockGap=8
//% parts="speaker"
void ringTone(int frequency) {
playTone(frequency, 0);
}
}