try to use uBit.soundmotor sound functions
This commit is contained in:
9
libs/core/music.cpp
Normal file
9
libs/core/music.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "ksbit.h"
|
||||
|
||||
namespace music {
|
||||
void playTone(int freqency, int ms) {
|
||||
uBit.soundmotor.Sound_On(freqency);
|
||||
if(ms > 0) uBit.sleep(ms);
|
||||
uBit.soundmotor.Sound_Off();
|
||||
}
|
||||
}
|
@ -137,13 +137,13 @@ namespace music {
|
||||
//% 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
|
||||
pins.analogSetPitchPin(AnalogPin.P29);
|
||||
pins.analogPitch(frequency, ms);
|
||||
pins.digitalWritePin(DigitalPin.P28, 0); // switch off the motor driver
|
||||
}
|
||||
// export function playTone(frequency: number, ms: number): void {
|
||||
// // TODO check timing
|
||||
// pins.digitalWritePin(DigitalPin.P28, 1); // switch on the motor driver
|
||||
// pins.analogSetPitchPin(AnalogPin.P29);
|
||||
// pins.analogPitch(frequency, ms);
|
||||
// pins.digitalWritePin(DigitalPin.P28, 0); // switch off the motor driver
|
||||
// }
|
||||
|
||||
/**
|
||||
* Plays a tone through ``speaker``.
|
||||
|
@ -23,6 +23,7 @@
|
||||
"led.cpp",
|
||||
"led.ts",
|
||||
"motors.cpp",
|
||||
"music.cpp",
|
||||
"music.ts",
|
||||
"pins.cpp",
|
||||
"pins.ts",
|
||||
|
Reference in New Issue
Block a user