Hey there, Im working with a code that uses two servos, and they run inmediatly after connect the arduino to the computer, I would want they run after push a button, but I have read many tutorials but nothing work with my code, can sombody help me, I know it has to be to easy but obviously not for me.
Here is the code:
#include <Servo.h>
//Variables
Servo servoYaw, servoPitch;
char s[15];
int yawAngle, pitchAngle;
const int buttonPin = 2;
int buttonState = 0;
void setup() {
//Servo init
servoYaw.attach(10);
servoPitch.attach(11);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
delay(5000);
//Sweep Yaw servomotor
for (yawAngle = 0; yawAngle <= 180; yawAngle += YAW_STEP) {
servoYaw.write(yawAngle);
//Sweep Pitch servomotor. The direction depends on the current directory
if (pitchAngle < 90) {
for (pitchAngle = 0; pitchAngle <= 180; pitchAngle += PITCH_STEP) {
servoPitch.write(pitchAngle);
sendMeasurement();
}
} else {
for (pitchAngle = 180; pitchAngle >= 0; pitchAngle -= PITCH_STEP) {
servoPitch.write(pitchAngle);
sendMeasurement();
}
}
}
}