Chronomètre avec enregistrement des tours (1 de 3)

// ********** setup du arduino 2 - le reciever par Sylvain Castel
// antenne apc 220 avec un cable qui relie la pin TX au RX0 du arduino ,le rest de l'antenne est connecté au ground et 5 volts
// un sensor de pression relié au analog2 ( et il y a une résistance de 10kohm entre le ground et le sensor)
// une led relié a la pin digital 13

// section pour définir la communication rf
int incomingByte = 0; // valeur recu par l'antenne rf - value recieved by rf transmission

// section de définitions pour le chronomètre - defenitions for the chronometer
unsigned long tempsPrecedent = 0, tempsActuel = 0,tempsTotal = 0; // mes variables de temps
unsigned long centitot1 = 0; // centieme to display
unsigned long secotot1 =0; // seconds to display
unsigned long minutot1 =0; // minutes to display

// définitons pour composantes hardware
int led5=13; // je definit le terme led5 au chiffre 13 - defines "led5" as the number 13select the input pin for the force sensor
int forcePin = 2; // pin analogue relie au force sensor - select the input pin for the force sensor
int val = 0; // variable représentant la valeur du force sensor -variable to store the value coming in from the sensor

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(led5, OUTPUT); // j'assigne la led5 comme un output pour y envoyer ou pas l'électricité a ma led - setting the led5, as usable
}

void loop() {
val = analogRead(forcePin); // lecture de la valeur qui vient du sensor de pression - read the value from the sensor

//début de section chronomètre relié au sensor analog2 -section start for chonometer with force sensor arduino2
if (val>500){ // si la valeur lue est plus que 500, alors exécute le code ci dessous entre{ } - if the value is maxed out or greater than 500
digitalWrite(led5,HIGH); // allume ma led car le sensor est écrasé- turns on LED 13 sensor is pressed

tempsTotal=tempsActuel - tempsPrecedent;
Serial.print("temps precedent: "); // here we print some text
Serial.println(tempsPrecedent);// here we print the preceding time
Serial.print("temps actuel: ");// here we print some text
Serial.println(tempsActuel);// here we print the actual time when the sensor was pressed
Serial.print("temps total: ");// here we print some text
Serial.println(tempsTotal);// here we print the total time in millis(tempsTotal=tempsActuel - tempsPrecedent;)

centitot1 = (tempsTotal%1000)/10 ; //centieme to display
secotot1 = (tempsTotal/1000)%60 ; // second to display
minutot1 = (tempsTotal/1000)/60 ; // minute to display

Serial.print("Votre temps: ");// here we print some text
Serial.print(minutot1);// we display minutes
Serial.print(":");// we sepate the minutes with :
Serial.print(secotot1);// we display seconds
Serial.print(":"); //we sepate the seconds with :
Serial.println(centitot1);// we display hundreds seconds

tempsPrecedent = tempsActuel; // ici on update la valeur de la variable temps précédent pour la prochain fois qu'on rentre dans le void loop -once we get our timing done, we update the value of the present time for the next time we go thru the void loop
delay(1000); //on attend une seconde pour éliminer les erreurs de double pression sur le sensor
}
else{ // si on a pas écrasé le sensor de pression
digitalWrite(led5,LOW); //éteint ma led - turn off led 13
tempsActuel = millis();// je defini la variable temps actuel a la fin

}

// fin section chronomèetre relié au sensor analog2 - end of chronometer lind to the sensor

if (Serial.available() > 0) {// ici on set pour recevoir de l'info - here we set up to recieve rf data

incomingByte = Serial.read();// definit une variable pour dire qu'on lit - variable to say we read or recieve data
if (incomingByte == 50){ // ici le chiffre 50 définit la valeur décimale du ''2'' envoyé en signal rf par la transmitter (aruidno1)

//debut du chronomèetre relié a la reception du signal - start of chrnometer with using the rf data as en event starter for chrono

digitalWrite(led5,HIGH);

tempsTotal=tempsActuel - tempsPrecedent;
Serial.print("temps precedent: ");
Serial.println(tempsPrecedent);
Serial.print("temps actuel: ");
Serial.println(tempsActuel);
Serial.print("temps total: ");
Serial.println(tempsTotal);

centitot1 = (tempsTotal%1000)/10 ; //centieme to display
secotot1 = (tempsTotal/1000)%60 ; // second to display
minutot1 = (tempsTotal/1000)/60 ; // minute to display

Serial.print("Votre temps: ");
Serial.print(minutot1);
Serial.print(":");
Serial.print(secotot1);
Serial.print(":");
Serial.println(centitot1);

tempsPrecedent = tempsActuel;
delay(500); // small pause so we dont hit twice in a row the sensor by mistake
}
else{
digitalWrite(led5,LOW); // on éteint la led 13 -turn off led 13
tempsActuel = millis();

// fin de section chronomètre relié a la reception d'un signal rf provenant du transmitter
}
// ici on a une section qui permet de debug les valeurs qui nous sont envoyées par les antennes rf
// here is a section where you can debug, and print the values recieved by your rf antenna

// say what rf antennas recieved:
//Serial.print("I received: ");
//example withSerial.println(incomingByte);
//Serial.println(tempsPrecedent, DEC);
}
}