fixed interface function names, add sound functionality
This commit is contained in:
@ -12,6 +12,12 @@ namespace motors {
|
||||
//% blockId=motor_on block="motor on at %percent|%"
|
||||
//% parts=dcmotor
|
||||
void motorOn(int power) {
|
||||
uBit.soundmotor.Motor_On(power);
|
||||
uBit.soundmotor.motorOn(power);
|
||||
}
|
||||
|
||||
void motorOff() {
|
||||
uBit.soundmotor.motorAOff();
|
||||
uBit.soundmotor.motorBOff();
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +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);
|
||||
uBit.soundmotor.soundOn(freqency);
|
||||
if(ms > 0) uBit.sleep(ms);
|
||||
uBit.soundmotor.Sound_Off();
|
||||
uBit.soundmotor.soundOff();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
@ -134,9 +134,9 @@ namespace music {
|
||||
* @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"
|
||||
// //% 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 {
|
||||
// // TODO check timing
|
||||
// pins.digitalWritePin(DigitalPin.P28, 1); // switch on the motor driver
|
||||
@ -152,13 +152,13 @@ namespace music {
|
||||
//% 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 {
|
||||
// TODO check timing
|
||||
pins.digitalWritePin(DigitalPin.P28, 1); // switch on the motor driver
|
||||
pins.analogSetPitchPin(AnalogPin.P29);
|
||||
pins.analogPitch(frequency, 0);
|
||||
pins.digitalWritePin(DigitalPin.P28, 0); // switch off the motor driver
|
||||
}
|
||||
// export function ringTone(frequency: number): void {
|
||||
// // TODO check timing
|
||||
// pins.digitalWritePin(DigitalPin.P28, 1); // switch on the motor driver
|
||||
// pins.analogSetPitchPin(AnalogPin.P29);
|
||||
// pins.analogPitch(frequency, 0);
|
||||
// pins.digitalWritePin(DigitalPin.P28, 0); // switch off the motor driver
|
||||
// }
|
||||
|
||||
/**
|
||||
* Rests (plays nothing) for a specified time through pin ``P0``.
|
||||
|
12
libs/core/shims.d.ts
vendored
12
libs/core/shims.d.ts
vendored
@ -524,6 +524,18 @@ 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;
|
||||
}
|
||||
declare namespace pins {
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user