当前位置: 技术问答>linux和unix
linux下用什么函数来控制蜂鸣器的发声??
来源: 互联网 发布时间:2015-11-14
本文导语: 我在linux下用qt进行界面的编写,需要使蜂鸣器发声音,应该怎样做呢,是不是有相应的函数可以进行调用,请各位达人帮忙啊 | QApplication::beep | 可以直接写端口,代码如下:...
我在linux下用qt进行界面的编写,需要使蜂鸣器发声音,应该怎样做呢,是不是有相应的函数可以进行调用,请各位达人帮忙啊
|
QApplication::beep
|
可以直接写端口,代码如下:
#include
#include
void play(unsigned int* freq, unsigned int* delay);
main()
{
int i;
unsigned int freq[]={ 330 , 392 , 330 , 294 , 330 , 392 ,
330 , 394 , 330 , 330 , 392 , 330 ,
294 , 262 , 294 , 330 , 392 , 294 ,
262 , 262 , 220 , 196 , 196 , 220 ,
262 , 294 , 330 , 262 , 0 } ;
unsigned int time[]={ 50 , 50 , 50 , 25 , 25 , 50 ,
25 , 25 , 100, 50 , 50 , 25 ,
25 , 50 , 50 , 25 , 25 , 100,
50 , 25 , 25 , 50 , 25 , 25 ,
50 , 25 , 25 , 100 };
unsigned int freq2[]={
196,262,262,262,330,294,262,294,330,294,262,
330,394,440,440,394,330,330,262,294,262,294,
330,294,262,230,230,196,262,440,394,330,330,
262,294,262,294,440,394,330,330,394,440,523,
394,330,330,262,294,262,294,330,294,262,230,
230,196,262,440,394,330,330,262,294,262,294,
440,394,330,330,394,440,523,394,330,330,262,
294,262,294,330,294,262,230,230,196,262,0
};
unsigned int time2[]={
25,38,12,25,25,38,12,25,12,12,56,25,25,50,25,
38,12,12,12,38,12,25,12,12,38,12,25,25,100,25,
38,12,12,12,38,12,25,25,38,12,25,25,100,25,38,
12,12,12,38,12,25,12,12,38,12,25,25,100,25,38,
12,12,12,38,12,25,25,38,12,25,25,100,25,38,12,
12,12,38,12,25,12,12,38,12,25,25,100
};
unsigned int freq_alert[]={
2000, 2400, 0
};
unsigned int time_alert[]={
50, 60
};
for(i = 0; i > 8),0x42);
bit=inb(0x61);
outb(3 | bit,0x61);
usleep(10000*delay);
outb(0xfc | bit,0x61);
}
#include
#include
void play(unsigned int* freq, unsigned int* delay);
main()
{
int i;
unsigned int freq[]={ 330 , 392 , 330 , 294 , 330 , 392 ,
330 , 394 , 330 , 330 , 392 , 330 ,
294 , 262 , 294 , 330 , 392 , 294 ,
262 , 262 , 220 , 196 , 196 , 220 ,
262 , 294 , 330 , 262 , 0 } ;
unsigned int time[]={ 50 , 50 , 50 , 25 , 25 , 50 ,
25 , 25 , 100, 50 , 50 , 25 ,
25 , 50 , 50 , 25 , 25 , 100,
50 , 25 , 25 , 50 , 25 , 25 ,
50 , 25 , 25 , 100 };
unsigned int freq2[]={
196,262,262,262,330,294,262,294,330,294,262,
330,394,440,440,394,330,330,262,294,262,294,
330,294,262,230,230,196,262,440,394,330,330,
262,294,262,294,440,394,330,330,394,440,523,
394,330,330,262,294,262,294,330,294,262,230,
230,196,262,440,394,330,330,262,294,262,294,
440,394,330,330,394,440,523,394,330,330,262,
294,262,294,330,294,262,230,230,196,262,0
};
unsigned int time2[]={
25,38,12,25,25,38,12,25,12,12,56,25,25,50,25,
38,12,12,12,38,12,25,12,12,38,12,25,25,100,25,
38,12,12,12,38,12,25,25,38,12,25,25,100,25,38,
12,12,12,38,12,25,12,12,38,12,25,25,100,25,38,
12,12,12,38,12,25,25,38,12,25,25,100,25,38,12,
12,12,38,12,25,12,12,38,12,25,25,100
};
unsigned int freq_alert[]={
2000, 2400, 0
};
unsigned int time_alert[]={
50, 60
};
for(i = 0; i > 8),0x42);
bit=inb(0x61);
outb(3 | bit,0x61);
usleep(10000*delay);
outb(0xfc | bit,0x61);
}