Pushbutton to reverse direction of continuous sero

Can somebody please give me arduino code that will make a continuous servo reverse direction when a pushbutton is pressed. Ive had no success trying to find code online or write my own. Thank you very much

Look at other pieces of code that "change something" when a button is pushed. Then replace the "something" with your code that ends a new signal to the servo.

I see what you're saying and I have tried that but it hasn't worked yet (Im very new). I have tried to combine the button example sketch and the servo sweep example sketch with no success how would I make that work?

Start with if (digitalRead(button)==HIGH) MyServo.write(70) ; else MyServo.write(110) ;Crude, but it should work (with some possible sideeffects due to the frequent calls to the servo - you may need delay(50) in the loop for this crude example. You need to work out the setup and create the MyServo variable, attach and so on.

You should use the debounce example, and instead of doing digitalWrite to turn a LED on/off you use MyServo.write

You can then look at the StateChange example, so a button push will reverse the direction for each push.

The trick is to do the most simple program first, and then add one small refinment at a time.

Search the forum for “toggle” as there have been numerous post in the past.

//zoomkat servo button toggle test 4-28-2012

#include <Servo.h>
int button = 5; //button pin, connect to ground to move servo
int press = 0;
Servo servo;
boolean toggle = true;

void setup()
{
  pinMode(button, INPUT); //arduino monitor pin state
  servo.attach(7); //pin for servo control signal
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press = digitalRead(button);
  if (press == LOW)
  {
    if(toggle)
    {
      servo.write(160);
      toggle = !toggle;
    }
    else
    {
      servo.write(20);
      toggle = !toggle;
    }
  }
  delay(500);  //delay for debounce
}
//zoomkat servo button toggle test 11-06-2014
//Powering a servo from the arduino usually *DOES NOT WORK*.

boolean toggleState; // hold current state of switch
boolean lastToggleState;  // hold last state to sense when switch is changed
long toggleTimer = millis();  // // debounce timer

#include <Servo.h>
int toggleSwitchPin = 5; //button pin, connect to ground to move servo
Servo servo;

void setup(){
  // setup stuff here
  pinMode(toggleSwitchPin, INPUT); //arduino monitor pin state
  servo.attach(7); //pin for servo control signal
  digitalWrite(5, HIGH); //enable pullups to make pin high
  Serial.begin(9600); // for debugging via serial monitor
  Serial.println("zoomkat servo button toggle test 11-06-2014"); // so I can keep track of what is loaded
  Serial.println();
}

void loop(){

  toggleState = digitalRead(toggleSwitchPin); 

  if (millis() - toggleTimer > 500){  // debounce switch 100ms timer
    if (toggleState && !lastToggleState) {  // if switch is on but was previously off
      lastToggleState = true;  // switch is now on
      toggleTimer = millis();  // reset timer
      // do stuff here
      servo.write(20); //initial servo position
      Serial.println("20"); //debugging
    }

    if (!toggleState && lastToggleState){  // if switch is off but was previously on
      lastToggleState = false; // switch is now off
      toggleTimer = millis(); // reset timer
      // do stuff here
      servo.write(160);
      Serial.println("160");
    }
  }
}