Adding power supply control in a ServoEaser code

Hi,
I'm controlling a servo using the ServoEaser library (GitHub - todbot/ServoEaser: Arduino library for servo easing)
What the code does it, when pressing a button a servo makes a list of moves and stops until the next time the button pressed
the servo is connected to a ATX power supply which controlled by arduino (simple like turning on led)

What i'm trying to do is to add power on before the servo moves and power off after the servo moves

power on > servo moves > power off (until the button will be pressed another time)

However i tried few methods and no one of them works...

Does any one have an idea how can i work this out ?

(i was only managed to turn on the ATX before the servo moves by pressing the button)

Thanks !
Maayan

Here's the code:

//
// ServoEaser4ButtonPlay.ino -- trigger a move list with a button
//
// 2011, TeamPneumo, Tod E. Kurt, http://todbot.com/blog/
//
//

#include <Servo.h>
#include "ServoEaser.h"

const int ledPin   = 13; 
const int servoPin  = 8;
const int buttonPin = 7;
const int atx = 53;
int servoFrameMillis = 20;  // minimum time between servo updates
Servo servo; 
ServoEaser servoEaser;
int myServoMovesCount1 = 8;


// configurable list of servo moves
ServoMove myServoMoves1[] = {
// angle, duration
    {25,  1700},
    {95,  1700},
    {95,  1700},
    {21,  1700},
    {21,  1700},
    {43,  1700},
    {43,  1700},
    {21,  1700},
};

void setup()
{
 pinMode(atx, OUTPUT);      
 digitalWrite(atx, HIGH);  //Power the ATX  OFF
 pinMode( buttonPin, INPUT_PULLUP); // turn on internal pullup resistor
 servo.attach( servoPin );
 servoEaser.begin(servo, servoFrameMillis);
}

void loop()
{
  servoEaser.update();
  // on button press, play moves once
  if( digitalRead(buttonPin) == HIGH   // button press
    && !servoEaser.isRunning()   // to trigger only if not running
  ) {
 digitalWrite(atx, LOW);  //Power the ATX  ON
 delay(2000); //Wait 2 sec
 servoEaser.play( myServoMoves1, myServoMovesCount1, 1 ); // do the servo moves
 delay(13600);// Wait  until the servo list will finish the moves list
 digitalWrite(atx, HIGH);  //Power the ATX  OFF
  }    
}

What happens when you run the code you posted ?

Why the delay(13600) ? You are testing servoEaser.isRunning() to stop a response to the button press whilst the sequence is running to prevent a subsequent button input starting it again. What you may need to do is to debounce the button input.

Hi,
When i'm running the code the atx (power supply) turns on for 15.6 secs(2000+13600) and power off, until the button is pressed again. the servo is NOT making his moves.
the delay (13600); is for waiting for the servo to end his move list which takes 13600 (1700X8)

the servoEaser.isRunning() is to stop a response to the button press while the sequence is running, and it's working fine without the ATX control lines, however the code acts the same like i mentioned above when running it without the servoEaser.isRunning() line.

Maayan

Anyone ? :~

Ignoring the servoEaser for the moment, can you get a sketch that just turns on the atx power and moves the servo to work? For preference, just use servo.Write and delay in setup to move the servo to a few different positions once the power is on.

Yes I can get it work with simple servo.Write, the thing is i must use some "easing" solution since i'm looking for that kind of servo movement... otherwise you were right servo.Write is quite simple...

Anyone ? :~

Whatever else is going on the servo moves don't seem to make much sense.

// configurable list of servo moves
ServoMove myServoMoves1[] = {
// angle, duration
    {25,  1700},
    {95,  1700},
    {95,  1700},
    {21,  1700},
    {21,  1700},
    {43,  1700},
    {43,  1700},
    {21,  1700},
};

2 moves to angle 95, one after the other. 2 moves to angle 21 one after the other. 2 moves to angle 43 one after the other.
Why ?

Looking at the example code, I suspect that servoEaser.update needs to be called frequently. Try getting rid of that delay(13600).

The sense in putting the same angle twice is kind of "delay" to tell the servo to stay in the same angle for a period of time instead of moving.
and i guess that i cannot use the delay function in the void loop, when i'm getting rid of the delay(13600) the power supply (atx) turns on and immediately off without letting the servo to do his moves.

Anyone know how i can make this happen without the delay function ?
i mean to: turn on the atx > servo move > turn off the atx, but still using the ServoEaser ?

i'm really stuck with this :~

Use servoEaser's isRunning function. Check it after you call update. If it's false, turn the atx power off.

Brilliant ! it's working !!! Many thanks wildbill
i just tested it and it's working perfectly !

here is the code:

#include <Servo.h>
#include "ServoEaser.h"

const int ledPin   = 13; 
const int servoPin  = 8;
const int buttonPin = 7;
const int atx = 53;
int servoFrameMillis = 20;  // minimum time between servo updates
Servo servo; 
ServoEaser servoEaser;
int myServoMovesCount1 = 8;


// configurable list of servo moves
ServoMove myServoMoves1[] = {
// angle, duration
    {25,  1700},
    {95,  1700},
    {95,  1700},
    {21,  1700},
    {21,  1700},
    {43,  1700},
    {43,  1700},
    {21,  1700},
};

void setup()
{
 pinMode(atx, OUTPUT);      
 digitalWrite(atx, HIGH);  //Power the ATX  OFF
 pinMode( buttonPin, INPUT_PULLUP); // turn on internal pullup resistor
 servo.attach( servoPin );
 servoEaser.begin(servo, servoFrameMillis);
}

void loop()
{
  servoEaser.update();
   if( servoEaser.isRunning())
    digitalWrite(atx, LOW);  //Power the ATX  ON
else
       digitalWrite(atx, HIGH);  //Power the ATX  OFF
  // on button press, play moves once
  if( digitalRead(buttonPin) == HIGH   // button press
   && !servoEaser.isRunning()   // to trigger only if not running
  ) {
 servoEaser.play( myServoMoves1, myServoMovesCount1, 1 ); // do the servo moves
}
}