#include <Servo.h>  // includes the servo library

Servo servo1;       // assigns servo variable

int buttonpin = 2;  // assigns button to pin 2 on the redboard

int press1;         // creates a variable to count button presses 

int potPin = A0;    // assigns potentiometer to pin 0

int motorPin = 9;   // assigns DC motor to pin 9

int potValue = 0;   // creates a variable to track potentiometer value

int motorValue = 0; // creates a variable to track DC motor value

void setup() {
  
 Serial.begin(9600);
 
 servo1.attach(10); // assigns servo motor to pin 10
 
 pinMode(buttonpin, INPUT); // assigns pushbutton as an input
 
 digitalWrite(2, HIGH);     // sets button state to high when not pressed
}

void loop() {
  
press1 = digitalRead(buttonpin);  // determines if button is being pushed

 if (press1 == LOW){              // if button is pressed tells the servo to rotate to 179 degrees, wait one second return to 10 degrees, then wait another second
   
   servo1.write(179);
   
   delay(1000);
   
   servo1.write(10);
   
   delay(1000);
 }
 potValue = analogRead(potPin);  // reads the position of the potentiometer
 
 motorValue = map(potValue, 0, 1023, 0, 255);  // maps the speed of the DC motor to the position of the potentiometer
 
 analogWrite(motorPin, motorValue);            // assigns the mapped postion of the potentiometer to DC motor as its speed
 
 Serial.print("potentiometer = " );            
 
 Serial.print(potValue);                       // prints to potentiometer position to the screen
 
 Serial.print("\t motor = ");
 
 Serial.println(motorValue);                   // prints the DC motor speed to the screen
 
 delay(2);    
}