Image

Homework_03-Servo Motor & LEDs-Jake Brzezicki

31 Oct

Homework_03-Servo Motor & LEDs-Jake Brzezicki

#include
Servo microservo;
int pot = 0;
int val;
int red = 3;//assigns LED to port
int blue = 5;
int green = 6;
void setup() {
microservo.attach(9);
pinMode(red, OUTPUT);//sets LED to output
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
}

void loop() {

val = analogRead(pot); //potentiometer controls motor
val = map(val, 0, 1023, 0, 179);
microservo.write(val);
delay(10);

pot = (analogRead(A0));
digitalWrite(green, HIGH);//LED is on
delay(pot);
/*digitalWrite(green, LOW);
delay(pot);*/
digitalWrite(red, HIGH);
delay(pot);
/*digitalWrite(red, LOW);
delay(pot);*/

digitalWrite(blue, HIGH);//LED is controlled by potentiometer
delay(pot);
digitalWrite(blue, LOW);
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