#include <SoftwareSerial.h>//使用软件串口,能讲数字口模拟成串口
SoftwareSerial BT(8, 9); //新建对象,接收脚为8,发送脚为9
char val; //存储接收的变量
void setup() {
Serial.begin(9600); //与电脑的串口连接
Serial.println("BT is ready!");
BT.begin(9600); //设置波特率
}
void loop() {
//如果串口接收到数据,就输出到蓝牙串口
if (Serial.available()) {
val = Serial.read();
BT.print(val);
} //如果接收到蓝牙模块的数据,输出到屏幕
if (BT.available()) {
val = BT.read();
Serial.print(val);
}
#include "pitches.h"
int melody[] = {
NOTE_C4,NOTE_G3,NOTE_G3,NOTE_A3,NOTE_G3,0,NOTE_B3,NOTE_C4
};
int noteDurations[] = {
4,8,8,4,4,4,4,4
};
void setup() {
for (int thisNote = 0;
thisNote<8;thisNote++)
{
int noteDuration = 1000/noteDurations[thisNote];
tone(8,melody[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration *1.30;
delay(pauseBetweenNotes);
no Tone(8);
}
}
void loop() {
no need to repeat the melody.
}
}
网友评论