📄 buzzer.c
字号:
/* * Description: * example for buzzer. * What is shown in this example: * 1. How to open buzzer * 2. How to make buzzer beep * 3. How to end the beep * * */#include <stdio.h>#include <errno.h>#include <sys/kd.h>#include <fcntl.h>int main(void){ int fd; unsigned int arg; char buf[128]; /*open buzzer*/ fd = open("/dev/console",O_WRONLY); if (fd == -1) { printf("open Failed. errno:%d\r\n", errno); return; } arg = 100; /*frequency*/ arg |= 0x0100; ioctl(fd, KDMKTONE, &arg); /*start beep*/ sleep(3); ioctl(fd, KDMKTONE, 0); /*end beep*/ printf("the buzzer beeped?...[Y][N]"); fgets(buf, sizeof(buf), stdin); close(fd);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -