Homework – 03 – Servo Motor – Tyler Cook

31 Oct

For this assignment I had the potentiometer control both the led lights as well as the servo.

20131031_173912

#include <Servo.h>
Servo myservo; // controls the servo

int pot = 0; // pin A0 to potentiometer
int val; // variable to read the value from the analog pin
int red = 3; // pin 3 is red led
int blue = 5; //pin 5 is blue led
int green = 6; //pin 6 is green led

void setup()
{
myservo.attach(9);
}

void loop()
{
val = analogRead(pot); // reads the potentiometer
val = map(val, 0, 1023, 0, 179); // value that the servo moves at
myservo.write(val); // moves the servo
delay(15); // waits for the servo move
pot = (analogRead (A0));
digitalWrite(red, HIGH); //turns red led on
digitalWrite(blue, HIGH); //turns blue led on
digitalWrite(green, HIGH); //turns green led on
delay(pot); //delays turning led off
digitalWrite(red, LOW); //turns red led off
digitalWrite(blue, LOW); //turns blue led off
digitalWrite(green, LOW); //turns green led off
delay(pot);

}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s