For hardware details, see COMPONENTS below.
Safety features:
- Doubled shaft collars
- Nylock nuts in stressed places
- Metal straps around pole ends in case holes crack (no cracks yet)
- Modified code so random flapping only if button pressed
- Modified flapping code for smoother parabolic motion
Arduino code:
// RoboRaptor by Claus Buchholz
#include <Servo.h>
Servo lw, rw; // left wing, right wing
const int of = 40; // offset to servo positions
const int le = 2, re = 3, r1 = 4, y1 = 5, r2 = 6, y2 = 7; // 6 LEDs
const int vo = 8; // voice
const int sw = 11; // switch
int lr = LOW, ly = LOW, ct = 0;
void setup()
{
lw.attach(9, 700, 2300); // VEX Servo motors - 1500 pulse width at center
rw.attach(10, 700, 2300);
pinMode(le, OUTPUT); digitalWrite(le, HIGH);
pinMode(re, OUTPUT); digitalWrite(re, HIGH);
pinMode(r1, OUTPUT); digitalWrite(r1, LOW);
pinMode(y1, OUTPUT); digitalWrite(y1, LOW);
pinMode(r2, OUTPUT); digitalWrite(r2, LOW);
pinMode(y2, OUTPUT); digitalWrite(y2, LOW);
pinMode(sw, INPUT_PULLUP);
pinMode(13, OUTPUT); digitalWrite(13, LOW);
lw.write(of+50); // idle positions
rw.write(180-of-50);
}
void loop()
{
int bt = digitalRead(sw);
if (bt==HIGH || (++ct>3 && random(100)<99)) { // if switch not pressed,
int ey = (random(100)<5) ? LOW : HIGH; // blink eyes at random
digitalWrite(le, ey);
digitalWrite(re, ey);
delay(100);
if (bt==HIGH) ct = 0;
return;
} // if switch pressed, flap wings and belch fire
for (int i=48; i>=0; i-=2)
{
int p = i*i/50;
lw.write(of+p); // wings up
rw.write(180-of-p);
delay(20);
}
digitalWrite(le, LOW); // eyes off
digitalWrite(re, LOW);
for (int i=0; i<100; i++)
{
tone(vo, 3000-3*i, 18); // screech
int p = (i<50) ? i*i/50 : 100-(100-i)*(100-i)/50;
lw.write(of+p); // step wings down
rw.write(180-of-p);
if (i%5==0) { // sequence red and yellow LEDs at random for fire
digitalWrite(r2, lr);
digitalWrite(y2, ly);
lr = (random(100)<10) ? LOW : HIGH;
ly = (random(100)<30) ? LOW : HIGH;
digitalWrite(r1, lr);
digitalWrite(y1, ly);
}
delay(20);
}
lr = ly = LOW;
digitalWrite(r1, lr); // fire off
digitalWrite(y1, ly);
digitalWrite(le, HIGH); // eyes on
digitalWrite(re, HIGH);
digitalWrite(13, HIGH);
delay(100);
digitalWrite(r2, lr); // fire off
digitalWrite(y2, ly);
digitalWrite(13, LOW);
for (int i=98; i>=50; i-=2)
{
int p = 100-(100-i)*(100-i)/50;
lw.write(of+p); // wings to glide
rw.write(180-of-p);
delay(20);
}
}