嗨,我正在尝试在 mbed 应用程序屏蔽上使用不同的声音频率来从歌曲中创建音调。虽然我已经获得了所有频率,但我似乎无法减慢速度,因为它只是在所有频率之间快速循环。我曾尝试使用 wait(); 功能,但这似乎无法正常工作。我将不胜感激有关如何纠正此或替代解决方案的一些想法。
这是我的代码
#include "mbed.h"
#include "C12832.h" // for the LCD
#include "LM75B.h" //for the temperature sensor
#include "MMA7660.h" //For the accelerometer
/***************************************************************************
Global Variables
***************************************************************************/
C12832 shld_lcd (D11, D13, D12, D7, D10); // LCD on the application shield
PwmOut spkr(D6); //speaker
float c = 262.0; //These are the different frequencies
float d = 294.0;
float e = 330.0;
float f = 349.0;
float g = 392.0;
float a = 440.0;
float b = 494.0;
float C = 523.0;
void hotLineBling() {
//Here I am trying to use the frequencies to play the tone
spkr.period(1/e);
spkr.period(1/e);
spkr.period(1/e);
wait(0.5f);
spkr.period(1/C);
spkr.period(1/a);
spkr.period(1/e);
wait(0.5f);
spkr.period(1/d);
spkr.period(1/a);
spkr.period(1/d);
wait(1.0);
spkr.period(1/C);
spkr.period(1/a);
spkr.period(1/e);
wait(0.5f);
spkr.period(1/d);
spkr.period(1/a);
spkr.period(1/d);
spkr.period(1/c);
wait(1.0);
spkr.period(1/C);
spkr.period(1/a);
spkr.period(1/e);
wait(0.5f);
spkr.period(1/d);
spkr.period(1/a);
spkr.period(1/d);
wait(5.0);
}
int main()
{
hotLineBling();
while (1) {
spkr = 0.5;
wait(0.2f); //wait a little
}
}