Show Posts
|
|
Pages: [1]
|
|
5
|
Forum 2005-2010 (read only) / Français / Re: Chronomètre avec enregistrement des tours (1 de 3)
|
on: May 07, 2010, 01:35:31 pm
|
|
Salut Dans le concept de départ les boutons changent de fonctions selon le processus en cours. Par exemple bouton 1 sers pour départ et arrêt. Si le chrono roule le bouton ne peut pas repartir le chrono donc il sers a l'arrêter. Une fois en mode relecture des laps les boutons 2 et 3 servent à changer de lap. Si tu me donne plus de details je pourrai te souligner quel portion pourrait être utile.
En passant il y a surement moyen de reduire la grosseur du code. Ce je vais faire dans la prochaine phase du prochaine en plus d'ajouter la possibilité d'avoir le chrono de plusieurs compétiteurs en simultané.
8-) Madkart
|
|
|
|
|
6
|
Forum 2005-2010 (read only) / Français / Re: Chronomètre avec enregistrement des tours (3 de 3)
|
on: April 03, 2010, 09:08:18 pm
|
La troisième partie  (je suis un peu gêné :  ) /* Chrono START/STOP/LAPS  * Develop by S.Barbeau March 2010 // 3 PART ---- Troisième partie ------------ */
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++ To read LAP TIME in EEPROM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     if(buttonState2 == HIGH && lastButtonState2 == LOW && out == HIGH){ // Check for button2 if press to display / Get Data from eprom blinking = false;          // turn off blinking, all timing  done previousMillis1 = 0; // to able to restart after reading startTime = 0 ;       // start time for stop watch addr = 0; //Starting adress for Eprom's Data // read  byte from the EEPROM lcd.clear(); lap = 1; while (out == HIGH) { buttonState1 = digitalRead(buttonPin1);         // read the button 1 state and store delay(40); buttonState2 = digitalRead(buttonPin2);  // read the button2 state and store delay(40); if(buttonState1 ==HIGH && lap >1){ lap --; delay(10); buttonState1 = LOW; } if(buttonState2 == HIGH && lap < nbrenr/3){ lap++; delay(10); buttonState2 == LOW; } lcd.setCursor(0,0); lcd.print("LAPs "); lcd.print(lap); lcd.print(": "); lcd.setCursor(8,0); val = EEPROM.read((lap*3)-3); if (val <10) { //If less then 10 seconds display need ajustement lcd.print("0"); // Add a zero for clean presentation } lcd.print(val,DEC); lcd.print(":"); lcd.setCursor(11,0); val = EEPROM.read((lap*3)-2); if (val <10) { //If less then 10 seconds display need ajustement lcd.print("0"); // Add a zero for clean presentation } lcd.print(val,DEC); lcd.print(".");
lcd.setCursor(14,0); val = EEPROM.read((lap*3)-1); lcd.print(val,DEC);
if (buttonState1 == HIGH && buttonState2 == HIGH){ out=LOW; } Serial.print("Out "); Serial.println(out,BIN); // buttonState = digitalRead(buttonPin);          // read the button 0 state and store buttonState1 = digitalRead(buttonPin1);         // read the button 1 state and store delay(5); buttonState2 = digitalRead(buttonPin2);    // read the button2 state and store delay(5); } out = HIGH; nbrenr == 0; lcd.clear(); // Clear LCD lcd.print(" T-TIME:"); // Preset display description lcd.setCursor(0,1); lcd.print("LAPTIME:"); // print Legend of display information     }     else{      lastButtonState = buttonState;     // store buttonState in lastButtonState, to compare next time      lastButtonState1 = buttonState1;   // store buttonState in lastButtonState, to compare next time      lastButtonState2 = buttonState2;   // store buttonState in lastButtonState, to compare next time     } // Display of time since Start  ///////     if (blinking == true){     // ---------Display continus time ---------------- //  elapsedTime =   millis() - startTime;      // store elapsed time  lcd.setCursor(8,0); // Set cursor position on LCD if (minutot1 <10) {  lcd.print("0"); }  lcd.print(minutot1); // Display minutes  lcd.setCursor(10,0); // Set cursor position on LCD          lcd.print(":");          lcd.setCursor(11,0); // Set cursor position on LCD  if (secotot1 <10) {  lcd.print("0"); }          lcd.print(secotot1); // display Seconds          lcd.setCursor(13,0); // Set cursor position on LCD  lcd.print(".");  lcd.setCursor(14,0); // Set cursor position on LCD if (centitot1<10) {  lcd.print("0"); }          lcd.print(centitot1);  // Display Hundred         } centitot1 = (elapsedTime%1000)/10 ; //centieme to display secotot1 = (elapsedTime/1000)%60 ;  // second to display minutot1 = (elapsedTime/1000)/60 ;  // minute to display }
|
|
|
|
|
7
|
Forum 2005-2010 (read only) / Français / Re: Chronomètre avec enregistrement des tours (2 de 3)
|
on: April 03, 2010, 09:04:29 pm
|
Voici la suite 2 de 3 le 3ième suit: /* Chrono START/STOP/LAPS  * Develop by S.Barbeau March 2010 // SECOND PART ---- Deuxième partie ------------ /*------------- STOP then display time & RESET ----------------------------*/     else if (buttonState == LOW && lastButtonState == HIGH && blinking == true){  // check for a high to low transition if true then stop the clock and report //Serial.print(" B0 r ");         //elapsedTime =  millis() - startTime;        // store elapsed time if (previousMillis1 ==0) { // to correct the delay comming from Processor and start button 0 push previousMillis1 = startTime; }     elapsedTime =   (millis() - (previousMillis1)); // store elapsed time starttime centitot1 = (elapsedTime%1000)/10 ; //centieme to display secotot1 = (elapsedTime/1000)%60 ;  // second to display minutot1 = (elapsedTime/1000)/60 ;  // minute to display         blinking = false;                  // turn off blinking, all timing  done         lastButtonState = buttonState;                     // store buttonState in lastButtonState, to compare next time        // Report elapsed time on LCD        //        lcd.setCursor(8,1); // Set cursor position on LCD        if (minutot1 <10) { //If less then 10 minutes display need ajustement          lcd.print("0"); // Add a zero for clean presentation         }        lcd.print(minutot1); // Display minutes        lcd.setCursor(10,1); // Set cursor position on LCD        lcd.print(":");        lcd.setCursor(11,1); // Set cursor position on LCD        if (secotot1 <10) { //If less then 10 seconds display need ajustement          lcd.print("0"); // Add a zero for clean presentation         }        lcd.print(secotot1); // Display Second        lcd.setCursor(13,1); // Set cursor position on LCD        lcd.print(".");        lcd.setCursor(14,1); // Set cursor position on LCD        if (centitot1<10) { // If less then 10 hundreds display need ajustement          lcd.print("0"); // Add a zero for clean presentation         }        lcd.print(centitot1);//Display Hundred    // send the last run to eprom memory after the start stop button press    EEPROM.write(addr++,minutot1); // write minutes to eprom    nbrenr++; // incrementation  of the number of eprom memory used        EEPROM.write(addr++,secotot1); // write secondes to eprom    nbrenr++; // incrementation  of the number of eprom memory used        EEPROM.write(addr++,centitot1); // write hundred to eprom    nbrenr++; // incrementation  of the number of eprom memory used      }     // Detect BUTTON1  /LAP  Display lap timming without stoping counting //////////////////////////////////////////     else if (buttonState1 == LOW && lastButtonState1 == HIGH && blinking == true){   // check for a high to low transition on button1   if (previousMillis1 ==0) { // to correct the delay comming from Processor and start button 0 push previousMillis1 = startTime; }     elapsedTime =   (millis() - (previousMillis1)); // store elapsed time starttime previousMillis1 = millis(); // centitot1 = (elapsedTime%1000)/10 ; //centieme to display secotot1 = (elapsedTime/1000)%60 ;  // second to display minutot1 = (elapsedTime/1000)/60 ;  // minute to display    //   blinking = true;             lastButtonState1 = buttonState1;        // store buttonState in lastButtonState, to compare next time       //    lcd.setCursor(0,1); // Set cursor position on LCD           lcd.setCursor(8,1); // Set cursor position on LCD         if (minutot1 <10) {          lcd.print("0");         }        lcd.print(minutot1); // Display minutes        lcd.setCursor(10,1); // Set cursor position on LCD        lcd.print(":");        lcd.setCursor(11,1); // Set cursor position on LCD        if (secotot1 <10) {          lcd.print("0");         }        lcd.print(secotot1); // display Seconds        lcd.setCursor(13,1); // Set cursor position on LCD        lcd.print(".");        lcd.setCursor(14,1); // Set cursor position on LCD         if (centitot1<10) {         lcd.print("0");         }         lcd.print(centitot1);  // Display Hundred           // EEPROM.write(addr++,minutot1); // write minutes to eprom     nbrenr++; // incrementation  of the number of eprom memory used EEPROM.write(addr++,secotot1); // write secondes to eprom     nbrenr++; // incrementation  of the number of eprom memory used EEPROM.write(addr++,centitot1); // write hundred to eprom     nbrenr++; // incrementation  of the number of eprom memory used     }
|
|
|
|
|
8
|
Forum 2005-2010 (read only) / Français / Chronomètre avec enregistrement des tours (1 de 3)
|
on: April 03, 2010, 09:01:39 pm
|
Bonjour C'est mon premier post ici et mon premier véritable programme sur Arduino: Il s'agit d'un chronomètre. Je l'ai développé sur Duemilanova. J'utilise un LCD 4 bits et 3 boutons poussoir. L'affichage présente un temps écoulé total et  le temps d'un tour (LAP). Bouton 1 = départ/arrêt du chrono, Bouton 2 = enregistrement et affichage du temps d'un tour. Une fois arrêté en pressant pour une seconde fois le bouton1, on peut en pressant (bouton 3) afficher le temps de chacun des tours. En utilisant les bouton 2 et 3 on peut naviguer dans les différents tours. Pour sortir du mode révision des tours, il faut presser bouton 2(dwn) et bouton 3(Up) simultanément ce qui remet le chrono à zéro et permet de partir une autre session. Pour l'instant je retient qu'une session. Les prochains développement seront pour le transfert des données et l'ajout de multi-session. Je suis sur que le code peut être plus compact. Tout les commentaires et suggestions sont bienvenues particulièrement pour le développement du programme extérieur. Madkart   ps: Pgm en deux partie /* Chrono START/STOP/LAPS  * Develop by S.Barbeau March 2010  * Inspired by Paul Badger 2008  * Demonstrates using millis(),  * making two things happen at once, printing fractions  *  * Physical setup: momentary switch connected to pin 6,7,8 pulldown resistor 1k, other sides connected toVCC *   * LCD : The circuit:  * LCD RS pin to digital pin 12  * LCD Enable pin to digital pin 11  * LCD D4 pin to digital pin 5  * LCD D5 pin to digital pin 4  * LCD D6 pin to digital pin 3  * LCD D7 pin to digital pin 2  * 10K resistor:  * ends to +5V and ground  * wiper to LCD VO pin (pin 3)  */ #include <LiquidCrystal.h> #include <EEPROM.h>
// const int ledPin =13;                   // LED connected to digital pin 13 const int buttonPin= 6;         // button 0 on pin 6 const int buttonPin1=7;         // button 1  on pin 7 const int buttonPin2=8; // button 2 on pin 8 boolean buttonState = LOW;          // variable to store button 0  state boolean buttonState1= LOW;          // varible to store button 1 state boolean buttonState2= LOW;          // variable to store button 2 state boolean lastButtonState= LOW;        // variable to store last button 0 state boolean lastButtonState1= LOW;        // variable to store last button 1 state boolean lastButtonState2= LOW;        // variable to store last button 2 state boolean blinking = false;          // condition for blinking - True is timer (CLOCK) = ON boolean out = HIGH;
int addr = 0;            // adress for memory storage int val; // for  eprom recording of intermediate chrono int nbrenr = 0; //number of recording in eprom // int array example //int l = lap[100];
unsigned long previousMillis1 = 0;  // variable to store last time LED was updated unsigned long startTime = 0 ;    // start time for stop watch unsigned long elapsedTime = 0 ;   // elapsed time for stop watch unsigned long centitot1 = 0; // centieme to display unsigned long secotot1 =0;  // seconds  to display unsigned long minutot1 =0; // minutes to display int lap = 1; // Lap counter for display on LCD LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins // void setup() {    Serial.begin(9600); //   pinMode(ledPin, OUTPUT);         // sets the digital pin as output    pinMode(buttonPin, INPUT);    // not really necessary, pins default to INPUT anyway    pinMode(buttonPin1, INPUT); // not really necessary, pins default to INPUT anyway    pinMode(buttonPin2, INPUT); // not really necessary, pins default to INPUT anyway // set up the LCD's number of rows and columns:    lcd.begin(16, 2);    lcd.clear();    lcd.print("VERSION V0.831f"); //Displays  version of the software    delay(3000); // Time for displays of soft version    lcd.clear();    lcd.setCursor(0,0); // Cursor position on 1st line , first position , Place le curseur sur LCD. 1er ligne , 1er place    lcd.print(" T-TIME:"); // print Legend of display information    lcd.print("     ");      // clean the end of line on LCD    lcd.setCursor(0,1); // Cursor position on 2nd line , first position , Place le curseur sur LCD. 2er ligne , 1er place    lcd.print("LAPTIME:"); // print Legend of display information    lcd.print("     ");      // clean the end of line on LCD   } /////-------------------- loop() ------------------//// void loop() {     // check for button press    buttonState = digitalRead(buttonPin);          // read the button 0 state and store    buttonState1 = digitalRead(buttonPin1);         // read the button 1 state and store    buttonState2 = digitalRead(buttonPin2);  // read the button2 state and store
/*------------- START----------------------------*/    if (buttonState == LOW && lastButtonState == HIGH  &&  blinking == false){   // check for a high to low transition Button 0       // if true start the clock       startTime = millis();                  // store the start time       blinking = true;                    // turn on blinking while timing   lcd.setCursor(8,1);  // Cursor position on 2nd line , first position , Place le curseur sur LCD. 2er ligne , 1er place   lcd.print("     ");       // clean the end of line on LCD   //addr = 0; // debug       //delay(5);                     // short delay to debounce switch if "needed"       lastButtonState = buttonState;                          // store buttonState 0 in lastButtonState 0, to compare next time       lastButtonState1 = buttonState1;                        // store buttonState 1 in lastButtonState 1, to compare next time       lastButtonState2 = buttonState2;                        // store buttonState 2 in lastButtonState 2, to compare next time     }
|
|
|
|
|