What's wrong ? Using servo motor

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

Do someone could explain me why ? :confused:

#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( 3s );
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;
}
}

if (s=60)oops

Oops ? :s

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

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( 3s );
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;
}
}
}
}

HugoMenager:
Oops ? :s

sorry, that should be oops3

You have a strange definition of "works"

(deleted)

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

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

See reply #6

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

Your idea of working must be different to mine.

Do you understand the difference between = and == ?

UKHeliBob:
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 ?

Yes.
That's a pretty big difference, don't you think?

Pretty big yeah :S

HugoMenager:
Pretty big yeah :S

Now that you know the difference do you still think that your code works ?