Advertisement
Guest User

bluetooth

a guest
Feb 15th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #define speedofcar 150 //the speed of the motors
  2.  
  3. #define rightspeed 5 //this is the pin beside the in1 //must be connected to digital pin with the sine wave
  4. #define leftspeed 10 //this is the pin beside the in4 //don't need to be written in the void setup
  5.  
  6. #define in1 6
  7. #define in2 7
  8. #define in3 8
  9. #define in4 9
  10.  
  11. void setup()
  12. {
  13. Serial.begin(9600);
  14. for (int i = 6; i <= 9; i++)
  15. {
  16. pinMode(i, OUTPUT);
  17. }
  18. }
  19.  
  20.  
  21. void forward();
  22. {
  23. digitalWrite(in1,); //according to the battery and motor test
  24. digitalWrite(in1,);
  25. digitalWrite(in1,);
  26. digitalWrite(in1,);
  27. analogWrite(leftspeed, speedofcar);
  28. analogWrite(rightspeed, speedofcar);
  29. }
  30.  
  31. void backward();
  32. {
  33. digitalWrite(in1,); //according to the battery and motor test
  34. digitalWrite(in1,);
  35. digitalWrite(in1,);
  36. digitalWrite(in1,);
  37. analogWrite(leftspeed, speedofcar);
  38. analogWrite(rightspeed, speedofcar);
  39. }
  40.  
  41. void right();
  42. {
  43. digitalWrite(in1,); //according to the battery and motor test
  44. digitalWrite(in1,);
  45. digitalWrite(in1,);
  46. digitalWrite(in1,);
  47. analogWrite(leftspeed, speedofcar);
  48. analogWrite(rightspeed, speedofcar);
  49. }
  50.  
  51. void left();
  52. {
  53. digitalWrite(in1,); //according to the battery and motor test
  54. digitalWrite(in1,);
  55. digitalWrite(in1,);
  56. digitalWrite(in1,);
  57. analogWrite(leftspeed, speedofcar);
  58. analogWrite(rightspeed, speedofcar);
  59. }
  60.  
  61. void stopp();
  62. {
  63. digitalWrite(in1, 0); //according to the battery and motor test
  64. digitalWrite(in1, 0);
  65. digitalWrite(in1, 0);
  66. digitalWrite(in1, 0);
  67. analogWrite(leftspeed, speedofcar);
  68. analogWrite(rightspeed, speedofcar);
  69. }
  70.  
  71.  
  72.  
  73. void loop() //bluetooth code
  74. {
  75. if (Serial.available() > 0)
  76. {
  77. char x = Serial.read();
  78. switch (x)
  79. {
  80. case 'F': forward(); break;
  81. case 'B': backward(); break;
  82. case 'R': right(); break;
  83. case 'L': left(); break;
  84. case 'S': stopp(); break;
  85.  
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement