Guest User

Untitled

a guest
May 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo engine1;
  4. int incomingByte =0;
  5. int pos_engine1 = 0;
  6. int mounting_pount = 21; //here the engine starts turning
  7. void setup()
  8. {
  9.   engine1.attach(8);
  10.   Serial.begin(9600);
  11. }
  12.  
  13. void loop()
  14. {
  15.  
  16.   if (Serial.available() > 0)
  17.   {
  18.     incomingByte = Serial.read();
  19.     Serial.println(incomingByte);
  20.    
  21.     if (incomingByte == 119 && pos_engine1 < 180)
  22.     {
  23.       if (pos_engine1 < 21)
  24.       {
  25.         pos_engine1 = 21;
  26.       }
  27.       else
  28.       {
  29.       pos_engine1 ++;
  30.       }
  31.     }
  32.    
  33.       else if (incomingByte == 115 && pos_engine1 > 0 && !pos_engine1 > 21)
  34.     {
  35.      
  36.       pos_engine1 --;
  37.     }
  38.    
  39.   }
  40.    engine1.write(pos_engine1);
  41.    Serial.println(pos_engine1);
  42. }
Add Comment
Please, Sign In to add comment