Montreal
Offline
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« 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 }
|
|
|
|
« Last Edit: April 03, 2010, 09:05:14 pm by Madkart »
|
Logged
|
|
|
|
|
Montreal
Offline
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« Reply #1 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 }
|
|
|
|
|
Logged
|
|
|
|
|
Montreal
Offline
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« Reply #2 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 }
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 34
Arduino rocks
|
 |
« Reply #3 on: May 06, 2010, 08:43:57 am » |
hey, salut je sais pas si tu peux m'aider. J'aimerai faire un chronomètre start-stop avec arduino.
en utilisant 3 boutons, un qui start le chrono un qui stop le chrono et un dernier bouton qui reset.
peux tu me donner un coup de main. y a pas grand docum ou tutoriel sur les millis merci!! Sylvain
|
|
|
|
|
Logged
|
|
|
|
|
Geneva
Offline
Faraday Member
Karma: 22
Posts: 2878
Yoplait... le pt'it suisse
|
 |
« Reply #4 on: May 06, 2010, 11:19:52 am » |
Va voir ici : Maîtrisez le temps ! tu remplaces la fonction SDL_GetTicks par millis() et tu fais tes bidouilles.... 
|
|
|
|
« Last Edit: May 06, 2010, 11:24:02 am by jfs »
|
Logged
|
MacBook intel core 2 duo os X snow Leopard 10.6 eMac PPc G4 os X Leopard 10.5 powerbook G4 os X Leopard 10.5 imac PPC G3 os X Panther 10.3.9 Arduino Diecimila Arduino Mega Arduino Standalone Arduino 1307.04 
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 34
Arduino rocks
|
 |
« Reply #5 on: May 06, 2010, 06:19:15 pm » |
Un gros merci! voici ce que j'ai récupéré en quelques minutes... je dois continuer a travailler le code pour que ca fasse ce que je veux mais c une bonne base!  merci encore: unsigned long tempsPrecedent = 0, tempsActuel = 0; void setup(){ Serial.begin(9600); } void loop(){ tempsActuel = millis(); if (tempsActuel - tempsPrecedent > 3000) /* Si 30 ms se sont écoulées */ { Serial.print("temps precedent: "); Serial.println(tempsPrecedent);/* On bouge Zozor */ Serial.print("temps actuel: "); Serial.println(tempsActuel); tempsPrecedent = tempsActuel; /* Le temps "actuel" devient le temps "precedent" pour nos futurs calculs */ } } 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 34
Arduino rocks
|
 |
« Reply #6 on: May 07, 2010, 12:02:12 am » |
10k ohm résistance un sensor de pression branché dans analog 2
a chaque écrasement du sensor, il sort le temps écoulé depuis le dernier écrasement du force sensor.
** com3: arduino : avec alimentation dans une prise de courant com4: arduino : alimenté par usb. com5: antennes rf
Mes 2 arduinos vont avoir le code ci dessous, puisque chacun d'eux ont un sensor de pression attaché au analog2.
Maintenant j'ai des problèmes avec la transmission RX tX, et mes antennes apc220. je ne suis pas cappable d'envoyer du premier arduino vers le deuxième, pour voir dans le serial monitor les temps du premier et du deuxième arduino.
Toute aide serait vraiment appréciée merci!!
/* --------------------------------------------
Make Magazine - Force Sensor Demo
This simple program visually shows the amount of force placed on the sensor There are much more efficient ways to program, this way was chosen because it is very easy to understand.
By Marc de Vinck - Licensed under Creative Commons....whatever.
-------------------------------------------- */
// Here are the constants that we define prior to the program running
int forcePin = 2; // select the input pin for the force sensor int val = 0; // variable to store the value coming in from the sensor int led5=13; // defines "led5" as the number 13 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
unsigned long inputVal =0;
// End of constant definitions
void setup() //run one time when the Arduino first powers up {Serial.begin(9600); //starts serial communication, only used for debgugging pinMode(led5, OUTPUT); } // remeber led5 = pin 13, this statement sets pin 13 to output only
void loop() //This next bit of code runs continuously { val = analogRead(forcePin); // read the value from the sensor //inputVal = Serial.read(); // Serial.println(inputVal, DEC);
//Serial.println(val,DEC); // print the value "val" of the sensor (used for debugging)
if (val>500){ //if the value is maxed out or greater than 250 digitalWrite(led5,HIGH); // turns on all 5 LEDs //delay(100); //slight delay to minimize flickering
tempsTotal=tempsActuel - tempsPrecedent; Serial.print("temps precedent: "); Serial.println(tempsPrecedent);/* On bouge Zozor */ 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(1000); } else{ digitalWrite(led5,LOW); //turn off led 13 tempsActuel = millis();
}
}
|
|
|
|
|
Logged
|
|
|
|
|
Geneva
Offline
Faraday Member
Karma: 22
Posts: 2878
Yoplait... le pt'it suisse
|
 |
« Reply #7 on: May 07, 2010, 12:32:00 am » |
|
|
|
|
|
Logged
|
MacBook intel core 2 duo os X snow Leopard 10.6 eMac PPc G4 os X Leopard 10.5 powerbook G4 os X Leopard 10.5 imac PPC G3 os X Panther 10.3.9 Arduino Diecimila Arduino Mega Arduino Standalone Arduino 1307.04 
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 34
Arduino rocks
|
 |
« Reply #8 on: May 07, 2010, 07:50:33 am » |
OK, je vais faire un tour sur tes liens, jusqu'a présent ils sont vraiment utiles! 
|
|
|
|
|
Logged
|
|
|
|
|
Montreal
Offline
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« Reply #9 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
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 34
Arduino rocks
|
 |
« Reply #10 on: May 07, 2010, 01:39:48 pm » |
Vraiment Kool, le dernier code que j'ai posté fonctionne très bien pour la question de chronométer j'ai ré-utilisé une petite parti de ton code pour calculer secondes,minutes et milli secondes.
la ou je suis bloqué est le rx tx des 2 arduinos, puisqu'un des arduino est branché en usb, et est supposé recevoir des pins rx tx 0 et 1.
mon module séparé envoie l'info mais je crois que le deuxième (branché usb+antenne rf) a un problème de communication usb/rx/tx. :S
:-?
|
|
|
|
|
Logged
|
|
|
|
|
Geneva
Offline
Faraday Member
Karma: 22
Posts: 2878
Yoplait... le pt'it suisse
|
 |
« Reply #11 on: May 07, 2010, 02:05:49 pm » |
Dans ce cas utilise une Mega, elle a plusieurs RxTx.
|
|
|
|
|
Logged
|
MacBook intel core 2 duo os X snow Leopard 10.6 eMac PPc G4 os X Leopard 10.5 powerbook G4 os X Leopard 10.5 imac PPC G3 os X Panther 10.3.9 Arduino Diecimila Arduino Mega Arduino Standalone Arduino 1307.04 
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 34
Arduino rocks
|
 |
« Reply #12 on: May 07, 2010, 02:14:18 pm » |
mais, c'est possible de faire ce que je veux? - aussi, j'ai déja acheté 2 Duemilanove :S - Faudrait-il que j'achète un écran lcd pour me faciliter la tache, surement qu'un écran couterai le même prix qu'un méga, sauf que j'aurais un component de plus... sinon je vais voir pour le rx tx. aussi, j'avais déja vu la docum sur le apc220, comment configurer etc. Tout fonctione parfaitement avec une antenne branché sur arduino et l'autre antenne branché à l'adapteur usb, peut-etre que je pourrais acheter une autre antenne et la brancher à mon deuxième arduino pour un total de 3 antennes. 1 antenne sur chaque arduino et 1 antennet qui recoit branché a l'adapteur usb pour apc 220. ou la piste moins cher, de continuer à tester la transmission rx tx+usb... : 
|
|
|
|
|
Logged
|
|
|
|
|
Celtic Kingdom
Offline
Sr. Member
Karma: 2
Posts: 455
hard oui no!!!
|
 |
« Reply #13 on: May 07, 2010, 04:42:04 pm » |
la ou je suis bloqué est le rx tx des 2 arduinos, puisqu'un des arduino est branché en usb, et est supposé recevoir des pins rx tx 0 et 1. Si je ne dis pas une bêtise, il est possible d'utiliser des E/S digitales pour faire de la communication série (j'utilise le principe pour piloter mes écrans LCD afin qu'ils ne soient pas "pollués" lors d'une connexion USB). surement qu'un écran couterai le même prix qu'un méga, sauf que j'aurais un component de plus... A priori, non; une version Méga est dans les 40~50 alors qu'un écran LCD 16x2 série prêt à l'emploi se trouvent couramment dans les 20~25. Et moins cher encore pour une version non série (avec le driver type HD44780 intégré), et enfin encore moins cher en pièce à monté soit-même -.^
|
|
|
|
|
Logged
|
|
|
|
|
Montreal
Offline
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« Reply #14 on: May 07, 2010, 07:38:19 pm » |
Salut Castel Pour ton problème de communication entre les arduino va voir ce lien http://absences.sofianaudry.com/en/node/10 Je crois que tu vas trouver une réponse intéressante à ta demande. Malheureusement en anglais mais il y a toujours moyen de faire un peu de traduction avec google en gros il propose d'utiliser I2C. Tout ce que tu as besoin pour réaliser le montage est quelques résistance (1.5k), des fils et la bibliothèque http://arduino.cc/en/Reference/Wire Bonne chance et tient nous au courant Madkart (devine a quoi me sert le chrono) 
|
|
|
|
|
Logged
|
|
|
|
|
|