Servo passing through 0 to reach another angle.


hi guys,

i starting using servo , trying make 2 axis turret move ir emitter. command smarphone, connected through ble module (which used)(hm-12). so, gather information smartphone. (1 downward, 3 left, 5 backward , 7 right)

but, time time, servo going banana : going angle set him passing through 0, not behavior i'm willing achieve.

i connected first servo port 8 , second port 9.

i think comes coding, since when swap ports servos, alway 1 on port 8 behaving oddly.

my code below, using angle betwin phone , ground (i don't know right word in english, hope it's clear enough) control servos, 's' means phone flat, nothing supposed move. attaching , detaching servos time allow me stop them when going nuts.

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

servo servo1;
servo servo2;

char data;

int inc = 0;
int inc2 = 0;
int angle =100;
int angle2 = 0;

void recupdata(char *_data);

void setup(){
  serial.begin(9600);
  serial1.begin(115200);
  servo1.attach(8);
  servo2.attach(9);
}

void loop(){
  //data = 's';
  recupdata(&data);
  switch(data){
   case '1' :
     if(inc<50)
       inc++;
     angle  = map(inc, 0, 50, 100, 179);
     servo1.attach(8);
     servo1.write(angle);
     break;
   case 's':
     servo1.detach();
     servo2.detach();
     break;
   case '5':
     if(inc>0)
       inc--;
     angle = map(inc, 0, 100, 100, 179);
     servo1.attach(8);
     servo1.write(angle);
     break;
   case '3' :
     if(inc2 < 100)
       inc2++;
     angle2 = map(inc2, 0, 100, 0, 179);
     servo2.attach(9);
     servo2.write(angle2);
     break;
   case '7' :
     if(inc2 > 0)
       inc2--;
     angle2 = map(inc2, 0, 100, 0, 179);
     servo2.attach(9);
     servo2.write(angle2);
     break;
  }
 
  delay(15);

  serial.print("servo1 : ");
  serial.print(angle, dec);
  serial.print("  inc : "); 
  serial.print(inc, dec); 
  serial.print("  servo2 : ");
  serial.print(angle2, dec);
  serial.print("  inc2 : ");
  serial.println(inc2, dec);   

 // servo::refrech();
}

void recupdata(char *_data){
  if(serial1.available()){
    *_data = serial1.read();
  }
  serial.println(*_data);
}


thanks reading , :)

to more precise, seems occurs when i'm in "case 5" on first servo when angle decreases.


Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Servo passing through 0 to reach another angle.


arduino

Comments

Popular posts from this blog

Valutazione Template - Joomla! Forum - community, help and support

SD Datastring Convention

First use of Arduino Uno : avrdude error on Blink uploading