The dog was illustrated on card stock that was cut out and mounted to a piece of cardboard. A hole was made in the cardboard for the servo motor which has the dog's tailed tapped to it.
When the Arduino sketch is started, the dog loops through the programmed emotions; first sadness, then alert, and finally happiness. I used for loops and delays to control how long long the dog stays in each emotional state as I could not get millis() working the way I wanted.
![]() |
Servo Schematic |
ServoDog Sketch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long time; | |
#include <Servo.h> | |
Servo myservo; | |
void setup(){ | |
myservo.attach(9); | |
} | |
void loop(){ | |
myservo.write(0); // move to starting position | |
int x = 0; | |
//alert state | |
for (x = 0; x <= 5; x++){ | |
myservo.write(90); | |
delay(1000); | |
} | |
//happy state | |
for (x = 5; x <= 15; x++){ | |
myservo.write(180); | |
delay(100); | |
myservo.write(90); | |
delay(100); | |
delay(300); | |
} | |
//opposite state | |
for (x = 15; x <= 20; x++){ | |
myservo.write(180); | |
delay(1000); | |
} | |
} |
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.