user70089: I'm fairly new to arduino, and on my own I'm trying to move a servo to the left and right using 2 buttons.  I've got it working for the most part, however when I hold the button down nothing happens, and when I finally release the servo moves a certain amount based on how long I was holding the button down.  I would like the servo to move when the button is being held down though.  The servo also occasionally moves oddly and sporadically.  I'm thinking its most likely a logic error in the code, but I can't figure it out.  Could someone please tell me what they think I've done wrong?  Thank you.
code:
#include <Servo.h>
Servo servo;

#define right 9
#define left 8

int angle = 90;
int angStep = 5;



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(right, INPUT_PULLUP);
  pinMode(left, INPUT_PULLUP);
  servo.attach(2);
  servo.write(angle);
  Serial.print("Begin");
  Serial.print('\n');
  Serial.print(angle);
  Serial.print(angle);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(left) == HIGH && angle < 180){
    angle += angStep;
    Serial.print(angle);
    Serial.print('\n');
    servo.write(angle);
    delay(50);
  }

  if (digitalRead(right) == HIGH && angle > 0){
    angle -= angStep;
    Serial.print(angle);
    Serial.print('\n');
    servo.write(angle);
    delay(50);
  }
}


user63900: I think it's because you are using a pullup resistor, so it's constantly HIGH instead of constantly LOW. Try changing HIGH and LOW to the opposite.

70089: <p>I'm fairly new to arduino, and on my own I'm trying to move a servo to the left and right using 2 buttons.  I've got it working for the most part, however when I hold the button down nothing happens, and when I finally release the servo moves a certain amount based on how long I was holding the button down.  I would like the servo to move when the button is being held down though.  The servo also occasionally moves oddly and sporadically.  I'm thinking its most likely a logic error in the code, but I can't figure it out.  Could someone please tell me what they think I've done wrong?  Thank you.</p>
<p>code:</p>
<pre><code>#include &lt;Servo.h&gt;
Servo servo;

#define right 9
#define left 8

int angle = 90;
int angStep = 5;



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(right, INPUT_PULLUP);
  pinMode(left, INPUT_PULLUP);
  servo.attach(2);
  servo.write(angle);
  Serial.print(&quot;Begin&quot;);
  Serial.print('\n');
  Serial.print(angle);
  Serial.print(angle);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(left) == HIGH &amp;&amp; angle &lt; 180){
    angle += angStep;
    Serial.print(angle);
    Serial.print('\n');
    servo.write(angle);
    delay(50);
  }

  if (digitalRead(right) == HIGH &amp;&amp; angle &gt; 0){
    angle -= angStep;
    Serial.print(angle);
    Serial.print('\n');
    servo.write(angle);
    delay(50);
  }
}
</code></pre>
 63900: <p>I think it's because you are using a pullup resistor, so it's constantly HIGH instead of constantly LOW. Try changing HIGH and LOW to the opposite.</p>
