HC-6, HC-10 change Name

HC-6  , HC-10  REF CODE



#include <SoftwareSerial.h>

SoftwareSerial BTSerial(2, 3); // SoftwareSerial(RX, TX)

bool isSendMsg = false;

byte buf[1024];
int cnt;

void setup()
{

  Serial.begin(9600);
 
  Serial.println("Hello!");

  BTSerial.begin(9600);

 // BTSerial.write("AT"); // write it to BT

 cnt = 0;

}

void loop(){



  while (BTSerial.available()){ // if BT sends something
 
    byte data = BTSerial.read();
 
    Serial.write(data); // write it to serial(serial monitor)
 
  }



  while (Serial.available()){ // if Serial has input(from serial monitor)
 
    byte data = Serial.read();

    buf[cnt++] = data;
    //Serial.println("AT");
 
    //BTSerial.write("AT");
    //Serial.write(data);
    //BTSerial.write(data); // write it to BT
    isSendMsg = true;
 
  }

  if(isSendMsg)
  {
    if(buf[0]=='1')
    {
      Serial.println("println AT");
      BTSerial.println("AT");
    }
    else if(buf[0]=='2')
    {
      Serial.println("println AT+VERS? ");
      BTSerial.println("AT+VERS?");
    }
    else if(buf[0]=='3')
    {
      Serial.println("println AT+ADDR? ");
      BTSerial.println("AT+ADDR?");
    }
    else if(buf[0]=='4')
    {
      Serial.println("println AT+CLEAR ");
      BTSerial.println("AT+CLEAR");
    }
    else if(buf[0]=='5')
    {
      Serial.println("println AT+NAMEble_novis02");
      BTSerial.println("AT+NAMEble_novis02");
    }
   
   
    isSendMsg = false;
    cnt = 0;
   
  }

}

댓글

이 블로그의 인기 게시물

mount 명령 ( 읽기 권한만 있는놈 쓰기 권한 주기 )

c# mqtt client example

비글본 블랙 고정 아이피 설정