servo case structure issue


hello,

i have created fsm servo. has 2 states. using switch/case structure motor getting 'stuck' in first case , im not sure why.

code:

code: [select]
#include <servo.h>

#define 1 1
#define 2 2


servo myservo1; //projector platform servo

unsigned long timer1; //define timer variable state 1 if statement

void setup()
{
  myservo1.attach(9);
}

void loop(){
 
  static int state = one; // initial state one.
 
  switch(state)
  {
    case one:
    myservo1.writemicroseconds(1374); // servo moving cw
    delay(5000);
    myservo1.writemicroseconds(1474); // servo stationary
    timer1 = millis();
    if (millis() - timer1 > 5000)
    {
      state = two;
    }
break;

    case two:
    for(int speedv1 = 0; speedv1 <= 100; speedv1 += 2) // loop ramp speed of servos
    {
      myservo1.writemicroseconds(1474 + speedv1); // speed increase 2 each iteration (servo 1) until servo reaches fullspeed (acw)
      delay(40); // delay between loop iterations
    }
    delay(5000);
    for(int speedv2 = 0; speedv2 <= 100; speedv2 += 2) // loop ramp down servo speed
    {
      myservo1.writemicroseconds(1574 - speedv2); // speed decrease 2 each iteration (servo 1) until servo stops
      delay(40); //delay between loop iterations
    }
    delay(2000);
    state = one;
    break;
  }
}
   
   


the motor seems stuck @
code: [select]
myservo1.writemicroseconds(1374); on first line of case 1. stuck mean motor continues rotate in clockwise fashion , not progress next writemicroseconds() statement after delay. appreciate help.

thanks

where these commands come ? looked @ servo library tutorial , didn't seem them. can post link getting these commands ?
code: [select]
myservo1.writemicroseconds(1374);


Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > servo case structure issue


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support