Guest User

Two for-loops, single variable

a guest
Nov 9th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include<Servo.h>
  2. Servo ServoUpDown; //Name your Servo-Motor
  3. Servo ServoLeftRight;
  4. int ServoActDelay=500;
  5. int LrAngles;
  6.  
  7. void setup()
  8. {
  9.   Serial.begin(9600);
  10.   ServoUpDown.attach(5); // Servo-Sensor PIN is no.5
  11.   ServoLeftRight.attach(9); //Servo-Sensor PIN is no.9
  12. }
  13.  
  14. void loop()
  15. {
  16.     delay(1000);
  17.  
  18.   for (LrAngles=90;LrAngles<=100;LrAngles=LrAngles+1)
  19.   {
  20.     Serial.print(" Turning ...., next angle is : ");Serial.println(LrAngles);
  21.     delay(200);
  22.      ServoLeftRight.write(LrAngles);
  23.     delay(1000);
  24.   }
  25.    
  26.  
  27.   for (LrAngles=100;LrAngles>90;LrAngles=LrAngles-1);
  28.   {
  29.     Serial.print(" Turning back..., next angle is : ");Serial.println(LrAngles);
  30.     delay(200);
  31.     ServoLeftRight.write(LrAngles);
  32.     delay(1000);
  33.   }
  34.  
  35.  
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment