【树梅派学习c++入门教学之演奏】

树莓派学习c++多分支结构的练习

#include
#include
#include

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;
}

你可能感兴趣的:(C++基础,树梅派,少儿编程,学习,c++,算法)