Advertisement
Guest User

Untitled

a guest
Aug 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. #include <Servo.h>
  3. Servo myservo;
  4. int rxPin = 7;
  5. int txPin = 8;
  6. SoftwareSerial bluetooth(rxPin, txPin);
  7.  
  8. String message; //string that stores the incoming message
  9.  
  10. void setup()
  11. {
  12. myservo.attach(11);
  13.  
  14.  
  15. Serial.begin(9600); //set baud rate
  16. bluetooth.begin(9600); //set baud rate
  17. }
  18.  
  19. void loop()
  20. {
  21.  
  22.  
  23. while(bluetooth.available()){
  24. message+=char(bluetooth.read());
  25.  
  26. }
  27. if(!bluetooth.available())
  28. {
  29. if(message!=""){
  30. int x = message.toInt();
  31. Serial.println(message); //show the data
  32. Serial.println(x); //show the data
  33. if (x<180){
  34. myservo.write(x);
  35.  
  36. message=""; //clear the data
  37. }
  38. }
  39. }
  40. delay(50); //delay
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement