mich29800

test_bluetooth

Jul 18th, 2021
1,385
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2. #define rxPin A0
  3. #define txPin A1
  4.  
  5. SoftwareSerial bluetooth =  SoftwareSerial(rxPin, txPin);
  6.  
  7. char state[4];
  8.  
  9. void setup()  {
  10.   pinMode(rxPin, INPUT);
  11.   pinMode(txPin, OUTPUT);
  12.   bluetooth.begin(115200);
  13.  
  14.   Serial.begin(9600);
  15.  
  16. }
  17.  
  18. void loop() {
  19. if(bluetooth.available() > 0)
  20.   {
  21.     for(int i=0;i<4;i++)
  22.     {
  23.     state[i] = bluetooth.read();
  24.     delay(2);
  25.    }
  26.  
  27.     for(int i=0;i<4;i++)
  28.     {Serial.print(state[i]);}
  29.     Serial.println();
  30.   }
  31.  
  32.    
  33.    
  34. }
RAW Paste Data