long startTime ; // start time for stop watch
long elapsedTime ;
int preincrementation = 8;
int vrai = 9;
float prevtension;// global variables are retained on each iteration of loop()
long time;
int valeurLue;
int analogPin = A0;
const int led = 13;
float tension; //variable pour stocker la valeur lue après conversion
void setup() {
pinMode(analogPin, INPUT);
pinMode( led, OUTPUT );
digitalWrite(led, HIGH);
delay (500);
digitalWrite(led, LOW); // 2.5cm
Serial.begin(115200);
}
void loop() {
prevtension = tension;
valeurLue = analogRead(analogPin);
//on traduit la valeur brute en tension (produit en croix)
tension = valeurLue * 5.0 / 1024;
long RPMactuel = 60000000 / elapsedTime;
long initime = 0.3 * elapsedTime;
long RPMconsigne = 3000;
long consigne = 60000000 / RPMconsigne;
if (tension < 2.8)
{
if (tension < (prevtension - 0.005)) { // compare them
elapsedTime = micros() - startTime;
startTime = micros();
digitalWrite(led, HIGH);
if(elapsedTime > consigne)
{
time = initime;
} // 4%
if(elapsedTime < consigne)
{
time = 4;
if ( (consigne - (consigne * 0.02)) < elapsedTime < (consigne + (consigne * 0.02)))
digitalWrite (preincrementation, HIGH);
{
if ( elapsedTime < consigne )
{
if ( elapsedTime > (consigne - (consigne * 0.0001)) )
{
time = 4;
time += 0.001;
}
if ( elapsedTime < (consigne + (consigne * 0.0001)) )
{
time = 4;
time -= 0.001;
}
if ((consigne - (consigne * 0.0001)) < elapsedTime < (consigne + (consigne * 0.0001)))
{
digitalWrite (vrai, HIGH);
}
}
}
delayMicroseconds (time);
digitalWrite(led, LOW); // do something, they are different
}
}
}
Serial.print("elapsedTime = ");
Serial.println(elapsedTime);
Serial.print("consigne = ");
Serial.println(consigne);
Serial.print("rpm actuel = ");
Serial.println(RPMactuel);
Serial.print("rpm consigne = ");
Serial.println(RPMconsigne);
Serial.print("initime = ");
Serial.println(initime);
Serial.print("time = ");
Serial.println(time);
Serial.println();
Serial.println();
}
Hi everyone first thank you for reading this message.
This is my code but the problem is that I want that my code count the time since the led is HIGH to the next led HIGH.
please help thank you
John