Robokitty created by me, Cody, Marissa &  Kayleigh. (Real kitty in the background is mine :)).

The arduino controls 2 servos and some LEDs. The original design had a 3rd servo which would rotate the head, however this proved hard to implement.
Code:
//////////////////////////////////////////////////////////////
#include <Servo.h>

const int ledPin = 11;
int eyebrightness = 0;

Servo paws;
int pawsValu = 50; //initial servo angle
int dir = 1;

Servo tail;
int tailValu = 50;
int dir2 = 1;
///////////////////////////////////////////////////////
void setup() {
//Serial.begin(9600);
pinMode(ledPin, OUTPUT);

paws.attach(5);
tail.attach(3);

}
//////////////////////////////////////////////////////
void loop() {

//control speed of paws/tail by adjusting ‘dir’ value and delay value

pawsValu = pawsValu + dir;
tailValu = tailValu + dir2;

if(pawsValu >= 100) {
dir = -5;
} else if(pawsValu <= 80){
dir = 5;}

paws.write(pawsValu);
if(tailValu >= 120) {
dir2 = -1;
}else if(tailValu <=30){
dir2 = 1;}

tail.write(tailValu);

eyebrightness = map(pawsValu, 65, 100, 0, 255); //eye brightness follows paws, somewhat
analogWrite(ledPin, eyebrightness);

delay(50);
//Serial.println(eyebrightness);
}

Advertisements