Programming push button to start timed Servo Sweep

Hello! I am 12 years old and just now learning how to code Arduino for a class I am taking. I am trying to make it so that when I push the button the code will begin to run. I'm trying to make the Servo move for 30 seconds, then the code changes for 15 seconds, then back to the beginning code for another 30 seconds with a single push of the button. I am trying to make the button start the code. When I press button 1 I would like the Servo to sweep from 0 to 60 quickly. Once it finishes that I would like it to sweep from 0 to 60 at a different speed. My Servo Control wire is on pin 3. Can anyone point me in the right direction? I am very new to the Arduino coding.

This is the base code I am trying to edit to make this happen:

/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

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

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

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

See BWD:

See State Machine Programming .

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.