going to try and write what i want to accomplish in a psuedo sketch first to try and make things easier.
in this project psuedo sketch i use both negative ( - ) and positive ( + ) to display if the servo should move clockwise ( + ) or counter clockwise ( - ).
-----------------to open the helmet----------------------------------
user presses the touch button , (normally open button1).
servo.2 tilts down/counter clockwise -15 degrees. (entire jaw tilts down -15 degrees)
takes 100ms to tilt the -15 degrees
servo.2 tilts up/clockwise +15 degrees. (the jaw splits,the users left side tilts up while the right side tilts down 15 degrees)
takes 100ms to tilt the +15 degrees
servo.3 rotates left/clockwise +30 degrees. (the left side positions itself out beyond the plane of the users head which
allows the needed clearance for step 8 )
takes 200ms to rotate the +30 degrees
servo.1 rotates counter clockwise -45 degrees. (the front face of the chin aligns with the rest of the jawbone to avoid
getting caught in the next step)
takes 300ms to rotate the -45 degrees
servo.2 tilts up/clockwise +125 degrees. (the left side tilts up along side the head)
all servos stay in their current positions until the button is pressed a second time. (at this point each jaw bone half will be
on the sides of the helmet)
---------------------- to close the helmet-----------------
at this point i want to be able to press button2 and pretty much do everything above accept in reverse to close the helmet.
user presses button. (consider the helmet fully opened before this is pressed)
servo.2 tilts down -125 degrees. (jaw tilts down from the side of the face)
takes 833ms to tilt the -125 degrees
servo.1 rotates in/clockwise +45degrees. (front face of chin goes back to its original position)
takes 300ms to rotate the +45 degrees
servo.3 rotates in/clockwise +30degrees. (the jaw rotates inward to be in front of the users face)
takes 200ms to rotate the +30 degrees
servo.2 tilts down/counter clockwise 15 degrees. (the jaw connects with the right side half)
takes 100ms to tilt the -15 degrees
servo.2 tilts up/clockwise +15 degrees. (the jaw now being connected as one piece tilts up to lock in place)
all servos stay in this closed state until the button1 is pressed. (helmet is considered closed at this point)
going to try and write it myself and report back with it.
#include <Servo.h>
int button = 5; //button pin, connect to ground to move servo
int press = 0;
Servo servo1;
Servo servo2;
Servo servo3;
boolean toggle = true;
void setup()
{
pinMode(button, INPUT); //arduino monitor pin state
servo1.attach(6); //pin for servo control signal
servo2.attach(7); //pin for servo control signal
servo3.attach(8); //pin for servo control signal
digitalWrite(5, HIGH); //enable pullups to make pin high
}
/*-----------------to open the helmet----------------------------------
user presses the touch button , (normally open button1).
servo.2 tilts down/counter clockwise -15 degrees. (entire jaw tilts down -15 degrees)
takes 100ms to tilt the -15 degrees
servo.2 tilts up/clockwise +15 degrees. (the jaw splits,the users left side tilts up while the right side tilts down 15 degrees)
takes 100ms to tilt the +15 degrees
servo.3 rotates left/clockwise +30 degrees. (the left side positions itself out beyond the plane of the users head which
allows the needed clearance for step 8 )
takes 200ms to rotate the +30 degrees
servo.1 rotates counter clockwise -45 degrees. (the front face of the chin aligns with the rest of the jawbone to avoid
getting caught in the next step)
takes 300ms to rotate the -45 degrees
servo.2 tilts up/clockwise +125 degrees. (the left side tilts up along side the head)
all servos stay in their current positions until the button is pressed a second time. (at this point each jaw bone half will be
on the sides of the helmet)
---------------------- to close the helmet-----------------
at this point i want to be able to press button2 and pretty much do everything above accept in reverse to close the helmet.
user presses button. (consider the helmet fully opened before this is pressed)
servo.2 tilts down -125 degrees. (jaw tilts down from the side of the face)
takes 833ms to tilt the -125 degrees
servo.1 rotates in/clockwise +45degrees. (front face of chin goes back to its original position)
takes 300ms to rotate the +45 degrees
servo.3 rotates in/clockwise +30degrees. (the jaw rotates inward to be in front of the users face)
takes 200ms to rotate the +30 degrees
servo.2 tilts down/counter clockwise 15 degrees. (the jaw connects with the right side half)
takes 100ms to tilt the -15 degrees
servo.2 tilts up/clockwise +15 degrees. (the jaw now being connected as one piece tilts up to lock in place)
all servos stay in this closed state until the button1 is pressed. (helmet is considered closed at this point)
*/
That way the logic of the code exactly matches how you think of the project and the technicalities of achieving the logic are each in their own compartment.
If there is nothing else for the sketch to do it is perfectly OK to uses delay() to manage the timing. But if you want to do other things while the servos are moving you should study the concept in the "blink without delay" example sketch.
i tried it with the delay and only the first servo would work, i tried taking out the delays and only 2 pf the 3 servos worked ....god i hate being a noob at writing sketches
Your description of the problem doesn't make sense to me.
If you are new to an Arduino start your project in small pieces.
Forget about reading buttons and using toggles. Just write a short sketch that causes your servos to move in the order you want. Then add in one piece of the control code, and then another.
Something like this (which I haven't tested) ...
By the way I don't think you can give negative values to servos so you will have to change those.
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
void setup()
{
servo1.attach(6); //pin for servo control signal
servo2.attach(7); //pin for servo control signal
servo3.attach(8); //pin for servo control signal
}
void loop()
{
servo2.write(-15);
delay (150);
servo2.write(15);
delay (150);
servo3.write(30);
delay (300);
servo1.write(-45);
delay (450);
servo2.write(125);
delay(5000);
servo2.write(0);
delay (1250);
servo1.write(0);
delay (450);
servo3.write(0);
delay (300);
servo2.write(0);
delay (150);
servo2.write(-15);
delay (150);
servo2.write(0);
delay(5000);
}
And wouldn't it be a lot more helpful to call them meaningful names such as jawServo and lipServo or whatever?
so this is essentially the movements i need at the very bare bones. next i really need help adding in 2 normally open push button to initiate each seperate part rather than using delay. i tried using boolean, and toggle and it just didnt work right... dont know i if i wrote it wrong but i used the same method of writing in the button as the original sketch i pasted first above these posts.
void setup()
{
servo1.attach(5); //pin for servo control signal
servo2.attach(6); //pin for servo control signal
servo3.attach(7); //pin for servo control signal
}
void loop()
{ servo2.write(15); //preps for negative movement
servo1.write(45); //preps for negative movement
delay(1000);
servo2.write(0); //makes it go negative 15 degrees
delay(1000);
servo2.write(15);
delay(1000);
servo3.write(30);
delay(1000);
servo1.write(0); //sets to negative 45 degrees
delay(1000);
servo2.write(140);
delay(10000);
servo2.write(0);
delay(1000);
servo1.write(45); //sets to zero position
delay(1000);
servo3.write(0);
delay(1000);
servo2.write(15);
delay(1000);
servo2.write(0);
delay(1000);
servo2.write(15);
delay(10000); //delay for debounce
}
/*-----------------to open the helmet----------------------------------
user presses the touch button , (normally open button1).
servo.2 tilts down/counter clockwise -15 degrees. (entire jaw tilts down -15 degrees)
takes 100ms to tilt the -15 degrees
servo.2 tilts up/clockwise +15 degrees. (the jaw splits,the users left side tilts up while the right side tilts down 15 degrees)
takes 100ms to tilt the +15 degrees
servo.3 rotates left/clockwise +30 degrees. (the left side positions itself out beyond the plane of the users head which
allows the needed clearance for step 8 )
takes 200ms to rotate the +30 degrees
servo.1 rotates counter clockwise -45 degrees. (the front face of the chin aligns with the rest of the jawbone to avoid
getting caught in the next step)
takes 300ms to rotate the -45 degrees
servo.2 tilts up/clockwise +125 degrees. (the left side tilts up along side the head)
all servos stay in their current positions until the button is pressed a second time. (at this point each jaw bone half will be
on the sides of the helmet)
---------------------- to close the helmet-----------------
at this point i want to be able to press button2 and pretty much do everything above accept in reverse to close the helmet.
user presses button. (consider the helmet fully opened before this is pressed)
servo.2 tilts down -125 degrees. (jaw tilts down from the side of the face)
takes 833ms to tilt the -125 degrees
servo.1 rotates in/clockwise +45degrees. (front face of chin goes back to its original position)
takes 300ms to rotate the +45 degrees
servo.3 rotates in/clockwise +30degrees. (the jaw rotates inward to be in front of the users face)
takes 200ms to rotate the +30 degrees
servo.2 tilts down/counter clockwise 15 degrees. (the jaw connects with the right side half)
takes 100ms to tilt the -15 degrees
servo.2 tilts up/clockwise +15 degrees. (the jaw now being connected as one piece tilts up to lock in place)
all servos stay in this closed state until the button1 is pressed. (helmet is considered closed at this point)
*/
Add your button code to this and when the buttons work properly fill out the jawOpen and jawClose functions to do what is needed. That way you can see where the problems are and we don't have to plough through long tracts of code that is irrelevant to the problem.