Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo servoLeft;
  4. Servo servoRight;
  5.  
  6. String readString;
  7. void sendInfo(int time, int speed);
  8. void Setup();
  9. void loop();
  10.  
  11. void setup()
  12. {
  13. Serial.begin(9600);
  14. servoLeft.writeMicroseconds(1500);
  15. servoRight.writeMicroseconds(1500);
  16. servoLeft.attach(13);
  17. servoRight.attach(12);
  18. }
  19. void loop()
  20. {
  21. /* Serial.begin(9600);
  22. servoLeft.writeMicroseconds(1500);
  23. servoRight.writeMicroseconds(1500);
  24. servoLeft.attach(13);
  25. servoRight.attach(12);*/
  26. Serial.println("WheelSet");
  27. int time;
  28. int speed;
  29. delay(1000);
  30. //Gets the time
  31. Serial.print("Please enter the time:");
  32. int k;
  33. readString="";
  34. while ((k = Serial.read()) != '\n')
  35. {
  36. if (k != -1)
  37. readString += (char) k;
  38. Serial.print((char) k);
  39. }
  40. if (readString.length() > 0)
  41. {
  42. Serial.println(readString); //so you can see the captured string
  43. time = readString.toInt(); //convert readString into a number
  44. time = time * 1000;
  45. Serial.print("Time: ");
  46. Serial.print(time);
  47. Serial.println("ms");
  48. }
  49.  
  50. //Gets the speed
  51. speed=0;
  52. Serial.println("Please enter the speed:");
  53. int x;
  54. readString="";
  55. while ((k = Serial.read()) != '\n')
  56. {
  57. if (k != -1)
  58. readString += (char) k;
  59. Serial.print((char) k);
  60. }
  61. if (readString.length() > 0)
  62. {
  63. //Serial.println(readString); //so you can see the captured string
  64. speed = readString.toInt(); //convert readString into a number
  65. }
  66.  
  67. //Sends the info
  68. // auto select appropriate value, copied from someone elses code.
  69. if(speed>=200)
  70. {
  71. Serial.print("writing Microseconds: ");
  72. Serial.println(speed);
  73. servoLeft.writeMicroseconds(speed);
  74. servoRight.writeMicroseconds(speed);
  75. }
  76.  
  77. delay(time);
  78. servoLeft.detach();
  79. servoRight.detach();
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement