该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
#include
#define B break
void de(int timee)
{
unsigned long int start,stop;
struct timeval str;
struct timeval stp;
gettimeofday(&str,NULL);
start=str.tv_usec;
while(1)
{ gettimeofday(&stp,NULL);
stop=stp.tv_usec;
if((stop-start)>timee)
B;
}
}
void tune(int tme)
{
int i;
for(i=0;i<200000/tme;i++)
{
digitalWrite(0,HIGH);de(tme);
digitalWrite(0,LOW);de(tme);
}
}
int main()
{
wiringPiSetup();
pinMode(0,OUTPUT);
char num;
while(1)
{
scanf("%c",&num);
printf("%c",num);
switch (num)
{
case '0' : delay(10);B;
case 'c' : tune(1465);B;
case 'd' : tune(1302);B;
case 'e' : tune(1172);B;
case 'f' : tune(1142);B;
case 'g' : tune(977);B;
case 'a' : tune(868);B;
case 'b' : tune(781);B;
}
}
return 0;
}
编译参数: gcc -Wall -o sound sound.c -lwiringPi