树梅派无源蜂鸣器
/**************************************** 时间:* 内容:无源蜂鸣器演奏,简单版****************************************/#include<wiringPi.h>
#include<softTone.h>
#include<iostream>using namespace std;const int BEEP = 0;//BCM 是17 //wPi 是 0
//tone是谱子 1318是音调,500是延时时间
int tone[][2] = {{1318,500},{1318,500},{1397,500},{1568,500},{1568,500},{1397,500},{1318,500},{1175,500},{1046,500},{1046,500},{1175,500},{1318,500},{1318,1000},{1175,250},{1175,500},{0,500}};
int main(){while(-1 == wiringPiSetup()){//使用Wpi模式cout << "error" << endl; }int len = sizeof(tone)/sizeof(tone[0]);softToneCreate(BEEP);while(1){for(int i=0; i < len; i++){softToneWrite(BEEP,tone[i][0]);delay(tone[i][1]);}}
}
C调音符与频率对照表