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
}