Go Down

Topic: What's wrong ? Using servo motor (Read 525 times) previous topic - next topic

HugoMenager

Hi, I tryed to write a program, but something dont work : servos are'nt moving :(

Do someone could explain me why ?  :smiley-confuse:

#include <Servo.h>
Servo servo_s;
Servo servo_m;
Servo servo_pin_10h
int m;
int h;
 
void setup()
{
   Serial.begin(9600);   // Vitesse de transmission compatible avec le fichier Processing.
   servo_s.attach(8);
   servo_m.attach(9);
   servo_h.attach(10); 
   servo_s.write( s );
   servo_m.write( m );
   servo_h.write( h );
   s=0;
   m=0;
   h=0;
}
   
void loop()
{
 
  servo_s.write( 3*s );
  servo_m.write( 3*m );
  servo_h.write( 7.5*h );

  delay (1000);
 
  s=s+1;
 
  if (s=60)
  {
    s=0;
    m=m+1;
  }
 
  m=m+s/60;
 
  if (m=60)
  {
    m=0;
    h=h+1;
  }
 
  h=h+m/60;
 
  if (h=24)
  {
     h=0;
  }
}

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.


Robin2

First of all you have not created a servo object called servo_h

Second the servo.write() function requires the number of degrees (between 0 and 180) that your servo should move to.

You seem to be trying to use a variable called 's' that you have not created.

The variables m and h will be initialized to 0 and I presume you know that (for example) 3 * 0 always gives 0

See what happens if you do something simple like servo_s.write(90);

All tests for the value of a variable require == for example if (s == 60) {


In general use meaningful names for all your variables, not single letters.

...R
Planning and Implementing a Program
Two or three hours spent thinking and reading documentation solves most programming problems.

HugoMenager

Ohh i understand !

It works no, thank you !!


#include <Servo.h>
Servo servo_s;
Servo servo_m;
Servo servo_h;
int s;
int m;
int h;

void setup()
{
Serial.begin(9600);   // Vitesse de transmission compatible avec le fichier Processing.
servo_s.attach(8);
servo_m.attach(9);
servo_h.attach(10);  
servo_s.write( s );
servo_m.write( m );
servo_h.write( h );
s=0;
m=0;
h=0;
}

void loop()
{

servo_s.write( 3*s );
servo_m.write( 3*m );
servo_h.write( 7.5*h );

delay (1000);

s=s+1;

if (s=60)
{
s=0;
m=m+1;
}

else
{
m=m+s/60;

if (m=60)
{
m=0;
h=h+1;
}

else
{
h=h+m/60;

if (h=24)
{
h=0;
}
}
}
}

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

AWOL

You have a strange definition of "works"
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

spycatcher2k

Code: [Select]
if (m=60)

This is WRONG - Robin2 Already told you this, and how to resolve it.
-=-
http://www.uk-pcb.co.uk - UK Based PCB Fab & Assembly Company
Design & Assembly work undertaken - Arduino repairs & testing - PM for details. Arduino & C# PC programming.

HugoMenager

It works without " == ", i just added "else" afet "if" :)

AWOL

It works without " == ", i just added "else" afet "if" :)
See reply #6
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

UKHeliBob

It works without " == ", i just added "else" afet "if" :)
Your idea of working must be different to mine.

Do you understand the difference between = and == ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

HugoMenager

Your idea of working must be different to mine.

Do you understand the difference between = and == ?
Not really.. Is "==" for testing something and "=" to change a value ?

AWOL

Yes.
That's a pretty big difference, don't you think?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

HugoMenager


UKHeliBob

Pretty big yeah :S
Now that you know the difference do you still think that your code works ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up