so im guessing these are the two scripts\commands i need to combine somehow. you were right to talk about how confusing state machine and FSM are. most other scripts ive learned kinda how to decypher but this however utterly makes no sense
...i had already created 3 - 3 AA battery packs one for each servo. the arduino is also on its own 9v battery pack. the thing i havent done yet i dont think is enabling a pull up or pull down resistor. ill research that as it probally is easy to find.i used the example script from your blinkwithoutdelay link so anywhere you see LED still in the script asume i mean servo
how do i stitch these sketches together to be able to accomplish my bellow series of servo actions. thank you again for all your support. im learning slowly but surely. once im finished with my project im going to make sure i put together a list of people who deserve credit where credit is due. it might help everyone involved to get a little more reputation hopefully. if you do not wish to be known for your help in my project just say so in the end of your posts.
-------------------to open the helmet----------------------------------
- user presses the touch button , (normally open switch).
- servo.2 tilts down/counter clockwise 15 degrees. (entire jaw tilts down -15 degrees)
- delay for 250ms
- servo.2 tilts up/clockwise 15 degrees. (the jaw splits,the users left side tilts up while the right side tilts down 15 degrees)
- delay for 250ms
- 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 )
- delay for 250ms
- 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)
- delay for 250ms
- 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 the button a second time and then 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)
- delay 250ms
- servo.1 rotates in/clockwise 45degrees. (front face of chin goes back to its original position)
- delay 250ms
- servo.3 rotates in/clockwise 30degrees. (the jaw rotates inward to be in front of the users face)
- delay 250ms
- servo.2 tilts down/counter clockwise 15 degrees. (the jaw connects with the right side half)
- delay 250ms
- 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 button is pressed again. (helmet is considered closed at this point)
----————————————————
// Which pins are connected to which LED
const byte servo.1 = 7;
const byte servo.2 = 8;
const byte servo.3 = 9;
// Time periods of blinks in milliseconds (1000 to a second).
const unsigned long servo.1interval = 500;
const unsigned long servo.2interval = 1000;
const unsigned long servo.3interval = 1500;
// Variable holding the timer value so far. One for each "Timer"
unsigned long servo.1timer;
unsigned long servo.2timer;
unsigned long servo.3timer;
void setup ()
{
pinMode (servo.1, OUTPUT);
pinMode (servo.2, OUTPUT);
pinMode (servo.3, OUTPUT);
servo.1timer = millis ();
servo.2timer = millis ();
servo.3timer = millis ();
} // end of setup
void toggleservo.1 ()
{
if (digitalRead (servo.1) == LOW)
digitalWrite (servo.1, HIGH);
else
digitalWrite (servo.1, LOW);
// remember when we toggled it
servo.1timer = millis ();
} // end of toggleservo.1
void toggleservo.2 ()
{
if (digitalRead (servo.2) == LOW)
digitalWrite (servo.2, HIGH);
else
digitalWrite (servo.2, LOW);
// remember when we toggled it
servo.2timer = millis ();
} // end of toggleservo.2
void loop ()
{
// Handling servo.1.
if ( (millis () - servo.1timer) >= servo.1interval)
toggleservo.1 ();
// Handling servo.2
if ( (millis () - servo.2timer) >= servo.2interval)
toggleservo.2 ();
// Handling servo.3
if ( (millis () - servo.3timer) >= servo.3interval)
toggleservo.3 ();
/* Other code that needs to execute goes here.
It will be called many thousand times per second because the above code
does not wait for the servo interval to finish. */
} // end of loop
-――――――—―—―—―
void loop(){
if (button.uniquePress()){
//increment buttonPresses and constrain it to [ 0, 1, 2, 3 ]
buttonPresses = ++buttonPresses % NUMBER_OF_STATES;
switch (buttonPresses){
case 0: ledStateMachine.transitionTo(On); break;
case 1: ledStateMachine.transitionTo(Off); break;
case 2: ledStateMachine.transitionTo(FadeIn); break;
case 3: ledStateMachine.transitionTo(FadeOut); break;
}