1、简单蜂鸣
pi@raspberrypi:~/training$ cat morse.c
#include <stdio.h>
#include <wiringPi.h>
int main(void) {
//初始化
wiringPiSetup();
// int pin = 8, t = 70;
int pin = 29, t = 70;
//设置针脚为输出状态
pinMode(pin, OUTPUT);
//定义摩尔斯电码示例 从A到H
char *morse_code = "01 1000 1010 100 0 0010 110 0000";
char *p=morse_code;
while(*p!='\0') {
switch(*p) {
//滴 响t秒 停t秒
case '0' : {
digitalWrite(pin,LOW);
delay(t);
digitalWrite(pin, HIGH);
delay(t);
};break;
//嗒 响3t秒 停t秒
case '1': {
digitalWrite(pin, LOW);
delay(t*3);
digitalWrite(pin, HIGH);
delay(t);
};break;
//字符间隔 中断3t秒
case ' ': {
delay(t*2);
};break;
}
p++;
}
//digitalWrite(pin, HIGH);
return 0;
}
2、演奏音乐