Hey everyone. I am working on a project for school where I have to make a mechanical duck. I am fairly new to the programming world and I need some help. I need to run three servos and a motor. One of the servos needs to move at a random time to a random angle between 0 and 180 degrees(for the head). The second needs to randomly turn to 180 degrees delay for a few seconds then turn back to 0(for raising the wings). The last one is a little bit trickier and involves the motor. I need the servo to turn from position 0 to position 180, turn the motor on for a second, turn the motor off then turn the servo back to position 0. Ill attach the code I have below.
I'm still new to coding so I'm not quite sure why its not working. I have one servo that seems to be clicking one degree every couple of seconds, and apart from that its showing no signs of working. Any help would be greatly appreciated!!!
#include <Servo.h>
Servo servo_head;
Servo servo_feathers;
Servo servo_wingpull;
int pos = 0;
int pull_feathers = 0;
int feathers_default = 0;
int timer = 0;
void setup() {
servo_head.attach(9);
servo_feathers.attach(10);
servo_wingpull.attach(6);
pinMode (8, OUTPUT);
}
void loop() {
int head_position = random(0,180);
servo_head.write(head_position);
int delay_time = random(1000,3000);
delay(delay_time);
for (timer < 30; timer += random(1,2);){
delay(1000);
}
if (timer >= 30) {
for (pull_feathers <= 180; pull_feathers += 1;) {
servo_feathers.write(pull_feathers);
}
}
if (pull_feathers = 180) {
digitalWrite(8, HIGH);
delay(2000);
digitalWrite(8, LOW);
servo_feathers.write(feathers_default);
}
int up_or_down = random(0,1);
if (up_or_down = 1){
servo_wingpull.write(180);
} else {
servo_wingpull.write(0);
}
}
So you edited your post, and instead of simply adding in some code tags, you removed the code completely, and attached it instead, thereby removing any hope of help from members on mobile devices.
A nasty thought occurs: might the compiler treat ("delay: " + (wait_time)) as a String? Arduino corp does not share my feelings about String objects on Arduino, I am sure since section 4 of the Built In Examples is a String-fest.