美文网首页
2020-01-07

2020-01-07

作者: gong圈圈 | 来源:发表于2020-01-07 19:13 被阅读0次

#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.
   }
}

相关文章

网友评论

      本文标题:2020-01-07

      本文链接:https://www.haomeiwen.com/subject/pejdactx.html