Advertisement
vencinachev

Robot-Niki

Apr 18th, 2022
1,382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftWareSerial.h>
  2.  
  3. #define M11 5
  4. #define M12 6
  5. #define M21 9
  6. #define M22 10
  7.  
  8. SoftwareSerial bt(3, 4); // RX, TX
  9. int msg;
  10.  
  11. void setup(){
  12.    bt.begin(9600);
  13.    pinMode(M11, OUTPUT);
  14.    pinMode(M12, OUTPUT);
  15.    pinMode(M21, OUTPUT);
  16.    pinMode(M22, OUTPUT);
  17. }
  18.  
  19. void loop(){
  20.   if(bt.available() > 0){
  21.      msg = bt.read();
  22.      switch (msg){
  23.         case 'F': forward(); break;
  24.         case 'B': backward(); break;
  25.         case 'L': left(); break;
  26.         case 'R': right(); break;
  27.         default: stop(); break;
  28.      }
  29.   }
  30.   delay(10);
  31. }
  32.  
  33.  
  34. void forward(){
  35.   digitalWrite(M11, HIGH);
  36.   digitalWrite(M12, LOW);
  37.   digitalWrite(M21, HIGH);
  38.   digitalWrite(M21, LOW);
  39. }
  40.  
  41.  
  42. void forward(){
  43.   digitalWrite(M11, HIGH);
  44.   digitalWrite(M12, LOW);
  45.   digitalWrite(M21, HIGH);
  46.   digitalWrite(M21, LOW);
  47. }
  48.  
  49.  
  50. void backward(){
  51.   digitalWrite(M11, LOW);
  52.   digitalWrite(M12, HIGH);
  53.   digitalWrite(M21, LOW);
  54.   digitalWrite(M21, HIGH);
  55. }
  56.  
  57.  
  58. void left(){
  59.   digitalWrite(M11, LOW);
  60.   digitalWrite(M12, HIGH);
  61.   digitalWrite(M21, HIGH);
  62.   digitalWrite(M21, LOW);
  63. }
  64.  
  65.  
  66. void right(){
  67.   digitalWrite(M11, HIGH);
  68.   digitalWrite(M12, LOW);
  69.   digitalWrite(M21, LOW);
  70.   digitalWrite(M21, HIGH);
  71. }
  72.  
  73. void stopp(){
  74.   digitalWrite(M11, LOW);
  75.   digitalWrite(M12, LOW);
  76.   digitalWrite(M21, LOW);
  77.   digitalWrite(M21, LOW);
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement