Hello guys can anyone please help me out with this code i want to perform this code in a loop. So that it repeated itself n no of times
#include <Servo.h>
Servo myservo;
#define pushButtonPin 2
int pos =0;
int buttonPushed =0;
void setup() {
myservo.attach(9);
pinMode (2,INPUT);
pinMode (pushButtonPin,INPUT_PULLUP);
}
void loop() {
myservo.write(pos);
if(digitalRead(pushButtonPin) == LOW){
buttonPushed = 1;
}
if( buttonPushed ){
pos = 200;
myservo.write(pos);
}
if (digitalRead(4) == LOW) //pin 4 is ir sensor
{
pos = 0;
myservo.write(pos); // if sensor is low servo will return to initial position
}
}
Source: Windows Questions C++