rev. 0.2 sound patches
This commit is contained in:
28
libs/core/music.cpp
Normal file
28
libs/core/music.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#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
|
||||
//% parts="speaker"
|
||||
void playTone(int freqency, int ms) {
|
||||
uBit.soundmotor.Sound_On(freqency);
|
||||
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);
|
||||
}
|
||||
}
|
@ -129,30 +129,30 @@ enum BeatFraction {
|
||||
namespace music {
|
||||
let beatsPerMinute: number = 120;
|
||||
|
||||
/**
|
||||
* Plays a tone through pin ``P0`` 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
|
||||
//% parts="speaker"
|
||||
export function playTone(frequency: number, ms: number): void {
|
||||
pins.analogSetPitchPin(AnalogPin.P0);
|
||||
pins.analogPitch(frequency, ms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a tone through pin ``P0``.
|
||||
* @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"
|
||||
export function ringTone(frequency: number): void {
|
||||
pins.analogSetPitchPin(AnalogPin.P0);
|
||||
pins.analogPitch(frequency, 0);
|
||||
}
|
||||
// /**
|
||||
// * Plays a tone through pin ``P0`` 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
|
||||
// //% parts="speaker"
|
||||
// export function playTone(frequency: number, ms: number): void {
|
||||
// pins.analogSetPitchPin(AnalogPin.P0);
|
||||
// pins.analogPitch(frequency, ms);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Plays a tone through pin ``P0``.
|
||||
// * @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"
|
||||
// export function ringTone(frequency: number): void {
|
||||
// pins.analogSetPitchPin(AnalogPin.P0);
|
||||
// pins.analogPitch(frequency, 0);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Rests (plays nothing) for a specified time through pin ``P0``.
|
||||
|
@ -23,6 +23,7 @@
|
||||
"led.cpp",
|
||||
"led.ts",
|
||||
"motors.cpp",
|
||||
"music.cpp",
|
||||
"music.ts",
|
||||
"pins.cpp",
|
||||
"pins.ts",
|
||||
|
21
libs/core/shims.d.ts
vendored
21
libs/core/shims.d.ts
vendored
@ -524,6 +524,27 @@ declare namespace motors {
|
||||
//% parts=dcmotor shim=motors::motorOn
|
||||
function motorOn(power: number): void;
|
||||
}
|
||||
declare 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
|
||||
//% parts="speaker" shim=music::playTone
|
||||
function playTone(freqency: number, ms: number): void;
|
||||
|
||||
/**
|
||||
* 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" shim=music::ringTone
|
||||
function ringTone(frequency: number): void;
|
||||
}
|
||||
declare namespace pins {
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user