Help Finishing Code To Control Servo

okay so what im trying to accomplish is activating a servo, with a push button, to go to 180 deg then return to 0deg. i modified code i found and accomplished some of what i am trying to do. it does the cycle i want. however the servo will cycle forever until i unplug from power instead of doing one cycle of 0deg - 180deg - 0deg by means of pressing the button one time. ive been trying for about 3 days here and there do get where i am now. any help would be greatly appreciated!

Here is my code without any button stuff… does a continuous 0 - 180 deg turn.

#include “Servo.h”

Servo myservo; // create servo object to control a servo, a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(7); // attaches the servo on pin 9 to the servo object
}

void loop()
{
unsigned long start = millis();
int sweepsNotFinished;

do
{
unsigned long now = millis() - start;
sweepsNotFinished = 0;
sweepsNotFinished += sweep(now, 500, 1500, -180, 180, myservo); // 1/4 second delay, then 9.75 second sweep from 30 to 100
} while (sweepsNotFinished > 0);
}

int sweep(unsigned long currentTime, unsigned long startTime, unsigned long endTime, int startPosition, int endPosition, Servo &servo)
{
if (currentTime < startTime)
return 1;
if (currentTime > endTime)
return 0;
servo.write( startPosition + (endPosition-startPosition) * (currentTime-startTime) / (endTime-startTime));
return 1;
}

im guessing if i want the button i would do something like this…

#include “Servo.h”

Servo myservo; // create servo object to control a servo, a maximum of eight servo objects can be created
int button1 = 4; //button pin
int press1 = 0; //setting button being pressed as active?? not sure what this does.
int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(7); // attaches the servo on pin 9 to the servo object
pinMode(button1, INPUT); //declare the button here???
digitalWrite(4, HIGH); //enable pullups to make pin high, NO IDEA WHAT THIS MEANS…
}

then add something like…

void loop ()
I have no idea how to add the button to the code. $H!T

however it is continuous

If it is a continuous rotation servo, it will be difficult to get it to go/return to a specific position.

zoomkat:
If it is a continuous rotation servo, it will be difficult to get it to go/return to a specific position.

sorry i will change the wording. i meant the servo moves continuously 0 - 180 - 0 - 180 etc until i unplug the power.

okay so what im trying to accomplish is activating a servo, with a push button, to do a 180 deg and return to 0.

Simple servo/button test code.

//zoomkat servo button test 7-30-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
    delay(2000);
    servo1.write(20);
  }
}
//zoomkat servo button test 7-30-2011
//Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
  }
  else {
    servo1.write(20);
  }
}