Infrared sensor controlling servo

/*pseudo code:
if distance is less then x {
turn servo clockwise 45 degrees
fade LEDs    }
if servo gets to 45 degrees {
turn counterclockwise to 0 degrees
brighten LEDs  }

*/

#include <Servo.h>

Servo jellyfish;
int pos = 0;

void setup() {

Serial.begin (9600); // (speed) sensor
jellyfish.attach(9);
}

void loop() {
int analogValue = analogRead(0);
Serial.println(analogValue);delay(10);

if (analogValue > 500) {
Serial.println(analogValue);
rebirth();
}
}

void rebirth() {
for(pos = 0; pos < 90; pos += 1) {
jellyfish.write(pos);
delay(10);
}
for(pos = 90; pos >=0; pos -= 1) {
jellyfish.write(pos);
delay(10); }

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

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

%d bloggers like this: