Last active
October 23, 2015 13:41
-
-
Save jasonhejna/e6024f93115b3f12c1ab to your computer and use it in GitHub Desktop.
Arduino Controlled Animatronic Skeleton
This file contains hidden or 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
#include <Stepper.h> | |
#include <Servo.h> | |
// create servo object | |
Servo myservo; | |
// instantiate a variable to store the servo position | |
int pos = 0; | |
// create an instance of the stepper class, specifying | |
// the number of steps of the motor and the pins it's | |
// attached to | |
#define STEPS 200 | |
Stepper stepper(STEPS, 4, 5, 6, 7); | |
void setup() | |
{ | |
// !!Turn on for USB debugging (Serial.println). define baud rate | |
//Serial.begin(9600); | |
// define laser on pins 13, and 12 | |
pinMode(13, OUTPUT); | |
pinMode(12, OUTPUT); | |
// define servo on pin 9 | |
myservo.attach(9); | |
// set the speed of the motor to 10 RPMs | |
stepper.setSpeed(10); | |
} | |
void loop() | |
{ | |
moveHead(); | |
delay(1000); | |
laserEyes2(); | |
delay(1000); | |
for (int i=0; i <= 1; i++){ | |
moveArm(); | |
delay(1000); | |
laserEyes1(); | |
delay(1000); | |
} | |
} | |
void moveArm() // Stepper Motor - 200 possible steps | |
{ | |
stepper.step(-26); // Arm Wind up | |
delay(50); | |
stepper.step(6); // Arm Swing | |
digitalWrite(4, LOW); | |
digitalWrite(5, LOW); | |
digitalWrite(6, LOW); | |
digitalWrite(7, LOW); | |
} | |
void laserEyes1() // Lasers On/Off | |
{ | |
for (int i=0; i <= 9; i++){ | |
digitalWrite(13, HIGH); | |
digitalWrite(12, LOW); | |
delay(400); | |
digitalWrite(13, LOW); | |
digitalWrite(12, HIGH); | |
delay(400); | |
} | |
digitalWrite(12, LOW); | |
} | |
void laserEyes2() // Lasers On/Off | |
{ | |
for (int i=0; i <= 9; i++){ | |
digitalWrite(13, HIGH); | |
digitalWrite(12, HIGH); | |
delay(400); | |
digitalWrite(13, LOW); | |
digitalWrite(12, LOW); | |
delay(250); | |
} | |
} | |
void moveHead() // Servo Motor | |
{ | |
for (pos = 60; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees | |
// in steps of 1 degree | |
myservo.write(pos); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
for (pos = 180; pos >= 60; pos -= 1) { // goes from 180 degrees to 0 degrees | |
myservo.write(pos); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment