kennyho-rass

l293pokusbt

Dec 16th, 2023
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <AFMotor.h>
  2. #include <Servo.h>
  3. #include <Wire.h>
  4. AF_DCMotor motor1 (1, MOTOR12_64KHZ);
  5. AF_DCMotor motor2(2, MOTOR12_64KHZ); // připojení DC motoru na konektor M2 64KHz pwm
  6. Servo myservo;
  7.  
  8. char command; // proměnná pro ukládání dat z Bluetooth modulu
  9. int val = 90;
  10. int pos = 10;
  11. void setup()
  12. {
  13. Serial.begin(9600); // set up Serial library at 9600 bps
  14. motor1.setSpeed(250);
  15. motor2.setSpeed(255);
  16. myservo.attach(9);
  17. myservo.write(90);
  18.  
  19. //}
  20.  
  21. //void loop() {
  22. // put your main code here, to run repeatedly:
  23. // if(Serial.availiable()) //Pokud je k dispozici sériový monitor, pokračuje smyčka mezi {a}
  24. //intstate=Serial.parseInt(); //nastaví „state“ na číslo, které bylo odesláno na sériový monitor
  25. //servo1.write(val);
  26. while (!Serial);
  27. Serial.println("-------------------------");
  28. Serial.println("ARos is loading....");
  29. delay(1000);
  30. Serial.println("ARos loaded succesfully");
  31. Serial.println("-------------------------");
  32. myservo.attach(9);
  33. Serial.println("calibrating servo...");
  34. for(pos = 0; pos <= 180; pos += 1)
  35. myservo.write(0);
  36. delay(1000);
  37. myservo.write(180);
  38. delay(1000);
  39. myservo.write(90);
  40. delay(1000);
  41. Serial.println("servo calibrated");
  42. Serial.println("-------------------------");
  43. Serial.println("Comand input online, write command to perform action");
  44. Serial.println("-------------------------");
  45.  
  46. }
  47.  
  48. void loop() {
  49.  
  50. for(pos = 0; pos <= 180; pos += 1)
  51. if (Serial.available())
  52.  
  53.  
  54. {
  55. int state = Serial.parseInt();
  56.  
  57. if (state < 10)
  58.  
  59. {
  60. Serial.print(">");
  61. Serial.println(state);
  62. Serial.println("cannost execute command, too low number");
  63.  
  64. }
  65.  
  66. if (state >= 10 && state < 170)
  67. {
  68. Serial.print(">");
  69. Serial.println(state);
  70. Serial.print("turning servo to ");
  71. Serial.print(state);
  72. Serial.println(" degrees");
  73. myservo.write(state);
  74.  
  75. }
  76.  
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment