How to increase variables slowly

Hello,

I'm looking to change my program, but I don't know how.
As you can see in my program, I have to change manually (ctrol + maj + M ) the variables, but I have to enter these variables (with a delay):

-20 ( 3sec = 3000ms )
-60 ( 3000ms )
-90 ( 3000ms )
-120 ( 3000ms )
-140 ( 3000ms )
-150(3000 ms )
-160 ( 3000ms)
-170 ( 3000ms ).

In the end, I simply want to connect the arduino board to a non-arduino pc and the program works by automatically increasing the variables.
Thanks.

Prgm :

#include <Servo.h>

Servo esc;
Servo esc2;// Création de l'objet permettant le contrôle de l'ESC

int val = 0;

void setup() {
esc.attach(9); // On attache l'ESC au port numérique 9 (port PWM obligatoire)²
Serial.begin(9600);
esc2.attach(10);
Serial.begin(9600 );

// Quelques informations pour l'utilisateur
Serial.println("Saisir un nombre entre 0 et 179");
Serial.println("(0 = arret - 179 = vitesse maxi");
(" demarrage a partir de 20)");
}

void loop() {
if (Serial.available() > 0) {
val = Serial.parseInt(); // lecture de la valeur passée par le port série
Serial.println(val);
esc.write(val);
delay(15);
esc2.write(val);
delay(15);
}
}

Hm .. maybe you could describe what you want to achieve?

criozola:
I'm looking to change my program, but I don't know how.
As you can see in my program,

Sorry but I don't understand what you want to achieve.

Maybe have a look at how the servo angle is gradually adjusted in the Servo Sweep example in the Arduino IDE.

...R

i just want to increase the speed of my 2 engines (and esc) without having to fill in serial.print a value. I have to gradually increase the serialprint value to 170, without having to go from 20 to 170 otherwise it will not work.

criozola:
-20 ( 3sec = 3000ms )
-60 ( 3000ms )
-90 ( 3000ms )
-120 ( 3000ms )
-140 ( 3000ms )
-150(3000 ms )
-160 ( 3000ms)
-170 ( 3000ms ).

In the end, I simply want to connect the arduino board to a non-arduino pc and the program works by automatically increasing the variables.

If that's really all you want to do it could be as simple as

      esc.write(20);
      esc2.write(20);
      delay(3000);
      esc.write(60);
      esc2.write(60);
      delay(3000);
      esc.write(90);
      esc2.write(90);
      delay(3000);
      // etc.

But I suspect there's more to it than that.

Steve

Ok thanks I will try this afternoon.

criozola:
-20 ( 3sec = 3000ms )
-60 ( 3000ms )
-90 ( 3000ms )
-120 ( 3000ms )
-140 ( 3000ms )
-150(3000 ms )
-160 ( 3000ms)
-170 ( 3000ms ).

What's wrong with something like:

  val = - (millis() - start_time) / 100 ;
  esc.write(val) ;

I guess it depends if the OP really needs val to increase by 40 then 30, 30, 20,10, etc. or if a fixed increase will work.

Steve

What's wrong ?

  #include <Servo.h>
 
Servo esc;
Servo esc2;// Création de l'objet permettant le contrôle de l'ESC

 
int val = 0;
 
 
void setup() {
   esc.attach(9); // On attache l'ESC au port numérique 9 (port PWM obligatoire)²
   Serial.begin(9600);
   esc2.attach(10);
   Serial.begin(9600  );
  
   }
 
void loop() {
      while (val < 170);
      val = - ( millis()-start_time / 100;
      esc.write(val); 
      esc2.write(val);
      };

Thanks

criozola:
What's wrong ?

You need to tell us what is wrong. You usually do that by stating:
I expected FOO to happen.
When my sketch ran, BAR happened instead.
If necessary, describe how FOO and BAR are different.

Edit: If you have compiler errors, click the Copy error messages button and paste them here using code tags.

Edit2: Look up the syntax of the while instruction and note how it uses curly brackets.
Your syntax for the assignment of val is off.
When you do get the while loop figired out, you will probably want a delay in it to slowly move from one end of the range to the other.