Advertisement
wluijkx

Untitled

Jan 19th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <Servo.h>
  3.  
  4. double angle_rad = PI/180.0;
  5. double angle_deg = 180.0/PI;
  6. double steering;
  7. Servo servo_9;
  8. char inputchar = char();
  9. String string1 = String();
  10. String commandype = String();
  11. String commandvalue = String();
  12.  
  13. void setup(){
  14. Serial.begin(57600);
  15. servo_9.attach(9); // init pin
  16. pinMode(2,OUTPUT);
  17. servo_9.write(90); // write to servo
  18. }
  19.  
  20. void receive_bt() {
  21. while(!((( inputchar==';'))))
  22. {
  23. _loop();
  24. while(!(Serial.available()))
  25. {
  26. _loop();
  27. }
  28. inputchar= char(Serial.read());
  29. string1 += inputchar;
  30. }
  31. }
  32. void loop(){
  33.  
  34. inputchar= "";
  35. string1= "";
  36. commandype= "";
  37. commandvalue= "";
  38.  
  39. receive_bt();
  40.  
  41. commandype= string1.substring(0, 1);
  42. commandvalue= string1.substring(1, string1.indexOf(';'));
  43. steering = (40) + commandvalue.toDouble();
  44.  
  45. tone(2,262,50); // write to buzzer to indicate data received
  46. delay(50);
  47.  
  48. Serial.print("New instructions recieved;");
  49. Serial.println(string1);
  50. Serial.println(commandype);
  51. Serial.println(commandvalue);
  52. Serial.println(steering);
  53.  
  54. servo_9.write(steering); // write to servo
  55. inputchar= "";
  56. string1= "";
  57. }
  58.  
  59. void _delay(float seconds){
  60. long endTime = millis() + seconds * 1000;
  61. while(millis() < endTime)_loop();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement