树莓派学习c++多分支结构的练习
#include<iostream>
#include<wiringPi.h>
#include<softTone.h>
using namespace std;
int t = 500;
int main(){
int BEEP = 25;
char a;
wiringPiSetup();
pinMode(BEEP,OUTPUT);
softToneCreate(BEEP);
while(true){
cin >> a;
if(a=='1') {
softToneWrite(BEEP,523);
delay(t);
softToneWrite(BEEP,0);
}else if(a=='2'){
softToneWrite(BEEP,587);
delay(t);
softToneWrite(BEEP,0);
}else if(a=='3'){
softToneWrite(BEEP,659);
delay(t);
softToneWrite(BEEP,0);
}else if(a=='4'){
softToneWrite(BEEP,698);
delay(t);
softToneWrite(BEEP,0);
}
else if(a=='5'){
softToneWrite(BEEP,784);
delay(t);
softToneWrite(BEEP,0);
}
else if(a=='6'){
softToneWrite(BEEP,880);
delay(t);
softToneWrite(BEEP,0);
}
else if(a=='7'){
softToneWrite(BEEP,988);
delay(t);
softToneWrite(BEEP,0);
}
}
return 0;
}