#define NOTE_FS7 2960
#define NOTE_G73136
#define NOTE_GS7 3322
#define NOTE_A73520
#define NOTE_AS7 3729
#define NOTE_B73951
#define NOTE_C84186
#define NOTE_CS8 4435
#define NOTE_D84699
#define NOTE_DS8 4978
//7个音符组成了美妙的音乐
//低Do re mi fa so la si do
int melody[] = {NOTE_C4, NOTE_D4,NOTE_E4, NOTE_F4, NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5};
//中Do re mi fa so la si do
int melody2[] = {NOTE_C5, NOTE_D5,NOTE_E5, NOTE_F5, NOTE_G5,NOTE_A5,NOTE_B5,NOTE_C6};
//高
int melody3[] = {NOTE_C6, NOTE_D6,NOTE_E6, NOTE_F6, NOTE_G6,NOTE_A6,NOTE_B6,NOTE_C7};
//PWM输出口
PwmOut m(PB_13);
//音调类
class Pitch{
public:
virtual void perfrom(int,double)=0;
void stop(double time = 0){
if(time==0)
m = 1;
else{
m = 1;
wait(time);
}//end else
}//end stop
};
class Low:public Pitch{
public:
void perfrom(int index,double time){
m.period_us(1000000/melody[index-1]);
m.write(0.5);
wait(time);
}
}
来源;21ic
关于控制,MCU就介绍完了,您有什么想法可以联系小编。