I admit that I am very new to programming in C++, so I am undoubtedly doing something very wrong. Ultimately my goal is to have two push buttons, one that turns a servo clockwise and one that turns it counterclockwise. When you push one button, the servo steps in one direction, and when it is released the servo stops. I am trying to start with one button, but am having trouble with the code. I would like it if when the button is pressed, the servo moves, and when it is released the servo stops. This is not working. Any ideas or guidance?
#include <Servo.h>
int button1 = 7; //buttonR pin, connect to ground to move servo
Servo servo1;
int pos = 0;
void setup()
{
pinMode(button1, INPUT);
servo1.attach(9);
digitalWrite(button1, HIGH); //enable pullups to make pin high
}
void loop()
{
int press1 = digitalRead(button1);
while (press1 == LOW);
{
servo1.write(pos);
pos++;
}
}