Rosey – Assignment 9

Description:

For my project, I was first inspired by the way servo motors seemed to have a similar range of motion as a wrist. Since the project was Halloween themed, I decided to make some skeleton-like hands to attach to the servos. From there, I just kept adding in more parts to make it seem like some robotic skeleton, including two red LEDs as eyes. The last thing I put in to make it slightly more interactive was a photocell that increased the speed of the servo and intensity of the light when covered.

Video:

Fritzing:

 

 Code:

#include 
const int sensorPin = 0;
const int ledPin1 = 5;
const int ledPin2 = 6;
Servo servoBlack;
Servo servoBlue;
int lightLevel;
int lightLevel2, high = 0, low = 1023;
int servoDelay;
int ledBright;

void setup(){
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  servoBlack.attach(10);
  servoBlue.attach(11);
  Serial.begin(9600);
}

void loop(){
  lightLevel = analogRead(sensorPin);
  lightLevel2 = analogRead(sensorPin);
  Serial.println(lightLevel);

  autoTune();
  analogWrite(ledPin1, ledBright);
  analogWrite(ledPin2, ledBright);

  servoDelay = map(lightLevel, 273, 700, 100, 20);
  int position;
  for(position = 0; position < 120; position += 2)
  {
    servoBlack.write(position);
    servoBlue.write(position);
    delay(servoDelay);
  }
}

void autoTune(){
  if (lightLevel2 < 700){     low = lightLevel;   }   if (lightLevel2 > 273){
    high = lightLevel;
  }

  ledBright = map(lightLevel2, 273, 675, 20, 255);
  ledBright = constrain(ledBright, 20, 255);
}

Post a comment