program issue

I have a sketch that uses servos and i need to get the servos to move slower and i cant figure out how. Where should or can i post the code for assistance in here, thanks in advance, Bob

Switched_6_Servos.ino (1.48 KB)

Read the first topic, "Guidelines.. how use Forum". #7 tells You how to attach code using so called "code tags", looking like </> to left in the reply window.
Tell what You want Your code to do and then what is actaullt happening. Attach wiring diagrams is sometimes needed….

If you were currently using Servo.h then you could just change to VarSpeedServo.h which has a speed parameter to the write() command.

Unfortunately I don't know anything about the antique SoftwareServo.h and the commands look somewhat different so I'm not sure how difficult a change to VarSpeedServo would be.

Steve

You can try doing the timing yourself if you stick with software servos. I modified your code and used Adafruit's software servo library. This compiles but may need additional debug etc...

//   MRH 6 Switched 6 Servos with Pushbuttons & LED Indicators
//   G. Bunza 2016
//
//#include <SoftwareServo.h>
#include <Adafruit_SoftServo.h>

#define K_NUMPINS           6                           // Number of Servos
#define K_STEPINTERVAL      5550ul                      // num uS/step; 135 steps takes ~750mS

//
const byte pins[]= { 14, 15, 16, 17, 18, 19 };          // Pushbutton/LED pins
const byte spins[]= { 2, 3, 4, 5, 6, 7 };               // Servo pins
const byte sstart[]= { 25, 57, 25, 25, 25, 25 };        // Servo Start Positions
const byte sstop[]= { 160, 100, 160, 160, 160, 160 };   // Servo Stop Positions

byte lastSw[K_NUMPINS] = {true};

typedef struct structSSControl
{
    Adafruit_SoftServo  objServo;
    unsigned long       stepInterval;    
    unsigned long       timerServo;
    byte                currPos;
    byte                tgtPos;
    bool                bMoving;
    bool                bDir;
        
}sSSControl;

sSSControl servos[K_NUMPINS]; 

boolean pinval[]= { true, true, true, true, true, true };  // Servo State

//
void setup() 
{
    InitServos();
    
    for( int i=0; i<K_NUMPINS; i++ )  
    {  
        pinMode( pins[i], OUTPUT );               // Initialize PB/LED pins
        digitalWrite( pins[i], HIGH );
        
    }//for
    
}//setup

void loop() 
{
    byte
        swNow;
    static byte
        index = 0;
        
    //needed for slower-motion
    ServosSpin();
    
    pinMode( pins[index], INPUT_PULLUP );
    swNow = digitalRead( pins[index] );            
    if( swNow != lastSw[index] )
    {
        lastSw[index] = swNow;
        if( swNow == LOW )
        {
            //uf pin differs from last read, toggle pinval
            pinval[index] = !pinval[index];
            //based on pin val, set the target position to start or stop
            servos[index].tgtPos = ( pinval[index] == true ) ? sstart[index]:sstop[index];
            
        }//if
        
    }//if
    
    pinMode( pins[index],OUTPUT );
    digitalWrite( pins[index], pinval[index] ); 

    index++;
    if( index == K_NUMPINS )
        index = 0;
    
}//loop


void InitServos( void )
{
    for( int idx=0; idx<K_NUMPINS; idx++ )
    {
        servos[idx].objServo.attach( spins[idx] );      //assign pin to servo object
        servos[idx].objServo.write( sstart[idx] );      //move servo to start position
        servos[idx].stepInterval = K_STEPINTERVAL;      //set up step-delay time
        servos[idx].timerServo = 0;                     //time keeping for this servo
        servos[idx].currPos = sstart[idx];              //set current and target positions (same at init)
        servos[idx].tgtPos = sstart[idx];
        servos[idx].bMoving = false;                    //not moving now
        servos[idx].bDir = true;                        //default "positive" step direction
                
    }//for
        
}//InitServos

void ServosSpin( void )
{
    unsigned long
        timeNow;
    static byte
        idx = 0;
    
    //timing using microseconds        
    timeNow = micros();

    //time for a step/check?
    if( timeNow - servos[idx].timerServo >= servos[idx].stepInterval )
    {
        servos[idx].timerServo = timeNow;
        //if moving now...        
        if( servos[idx].bMoving == true )
        {
            //move another step in the direction we're stepping
            if( servos[idx].bDir == true )
                servos[idx].currPos++;
            else
                servos[idx].currPos--;
                
            //and set the new step position    
            servos[idx].objServo.write( servos[idx].currPos );

            //have we reached the target position?
            if( servos[idx].currPos == servos[idx].tgtPos )
                servos[idx].bMoving = false;    //yes, clear the move flag to stop
                
        }//if
        
    }//if
    else
    {
        //not moving now; should we start?
        if( servos[idx].currPos != servos[idx].tgtPos )
        {
            //yes; set the direction
            servos[idx].bDir = (servos[idx].currPos > servos[idx].tgtPos) ? false:true;
            servos[idx].bMoving = true; //and set the moving flag
            
        }//if
        
    }//else

    //refresh servo each pass
    servos[idx].objServo.refresh();

    idx++;
    if( idx == K_NUMPINS )
        idx = 0;
    
}//ServosSpin

You can start with the servo "sweep" example in the IDE.

To put your code in a code box, use the </> icon in the far left of the post tool bar and paste your code between the two bracket sets that appear.

To go back and put your code in a code box, in the bottom right of your post, select "more" and click modify. When the modify post opens, high light your code and click the </> in the far left of the post tool bar. This will put you code in code brackets. Then save the changes.