Bonjour à tous !
Je travail à la conception d'un chronomètre qui démarre avec un interrupteur et qui est stoppé par un piezo (style Knock sensor). mais le tout sans fil. L'interrupteur est relié à un arduino et le piezo à un autre arduino. J'utilise les modules cheapo 433Mhz. La communication sans fil entre les 2 arduinos est parfaites et répond très bien. j'utilise la library rc switch. Sauf que dès que j'incorpore un sketch stopwatch le chrono démarre et arrête aussitôt sans avoir le temps de voir l'affichage. Y aurais t_il une solution simple sans utiliser de librairie.
Merci
bonjour,
un code peut être a nous monter?
Voici le code
#include<Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
//Config Pin
unsigned int data = 0;
const int startButton = 4;
#define rfReceivePin 4
int buzzer = 3;
int led = 2;
int buttonState; // variable to store button state
int lastButtonState; // variable to store last button state
int blinking; // condition for blinking - timer is timing
int frameRate = 100; // the frame rate (frames per second) at which the stopwatch runs - Change to suit
long interval = (1000/frameRate); // blink interval
long previousMillis = 0; // variable to store last time LED was updated
long startTime ; // start time for stop watch
long elapsedTime ; // elapsed time for stop watch
int fractional; // variable used to store fractional part of Frames
int fractionalSecs; // variable used to store fractional part of Seconds
int fractionalMins; // variable used to store fractional part of Minutes
int elapsedFrames; // elapsed frames for stop watch
int elapsedSeconds; // elapsed seconds for stop watch
int elapsedMinutes; // elapsed Minutes for stop watch
char buf[10];
void setup()
{
pinMode (startButton,INPUT);
pinMode (buzzer,OUTPUT);
pinMode (led,OUTPUT);
digitalWrite(startButton,LOW);
Serial.begin(9600);
//Print sur ecran de départ
lcd.begin (16,2);
Serial.begin (9600);
lcd.print ("REALISE PAR:");
delay(2000);
lcd.setCursor (3,1);
lcd.print ("REAL GAMER");
delay (2000);
lcd.clear();
lcd.setCursor(6,0);
lcd.print("POUR");
delay(2000);
lcd.setCursor (3,1);
lcd.print ("AIRSOFT QC.");
delay (4000);
lcd.clear();
delay(10);
lcd.print("APPUYEZ START");
}
void loop()
{
buttonState = digitalRead (startButton);
if (buttonState == LOW && lastButtonState == HIGH && blinking == false)
{
delay(10);
digitalWrite (buzzer,HIGH);
delay(500);
digitalWrite (buzzer,LOW);
delay(500);
digitalWrite (buzzer,HIGH);
delay(500);
digitalWrite (buzzer,LOW);
delay(500);
digitalWrite (buzzer,HIGH);
delay (500);
digitalWrite (buzzer,LOW);
delay(500);
digitalWrite (buzzer,HIGH);
delay(1000);
digitalWrite (buzzer,LOW);
startTime = millis(); // store the start time
blinking = true; // turn on blinking while timing
delay(10); // short delay to debounce switch
}
else if (buttonState == LOW && lastButtonState == HIGH && blinking == true) {
blinking = false;
Serial.println (data);
// Routine to report elapsed time
elapsedTime = millis() - startTime; // store elapsed time
elapsedMinutes = (elapsedTime / 60000L);
elapsedSeconds = (elapsedTime / 1000L); // divide by 1000 to convert to seconds - then cast to an int to print
elapsedFrames = (elapsedTime / interval); // divide by 100 to convert to 1/100 of a second - then cast to an int to print
fractional = (int)(elapsedFrames % frameRate); // use modulo operator to get fractional part of 100 Seconds
fractionalSecs = (int)(elapsedSeconds % 60L); // use modulo operator to get fractional part of 60 Seconds
fractionalMins = (int)(elapsedMinutes % 60L); // use modulo operator to get fractional part of 60 Minutes
delay (5000);
lcd.setCursor(0,1);
lcd.print (" REJOUER/START ");
delay(100);
}
if (fractionalMins < 10){ // pad in leading zeros
lcd.print("0"); // add a zero
}
lcd.print(itoa(fractionalMins, buf, 10)); // convert the int to a string and print a fractional part of 60 Minutes to the LCD
lcd.print(":"); //print a colan.
if (fractionalSecs < 10){ // pad in leading zeros
lcd.print("0"); // add a zero
}
lcd.print(itoa(fractionalSecs, buf, 10)); // convert the int to a string and print a fractional part of 60 Seconds to the LCD
lcd.print(":"); //print a colan.
if (fractional < 10){ // pad in leading zeros
lcd.print("0"); // add a zero
}
lcd.print(itoa(fractional, buf, 10));// convert the int to a string and print a fractional part of 25 Frames to the LCD
// run commands at the specified time interval
// blink routine - blink the LED while timing
// check to see if it's time to blink the LED; that is, the difference
// between the current time and last time we blinked the LED is larger than
// the interval at which we want to blink the LED.
if ( (millis() - previousMillis > interval) ) {
if (blinking == true){
previousMillis = millis(); // remember the last time we blinked the LED
lcd.setCursor(2,1);
lcd.print (" Go!Go!Go!");
elapsedTime = millis() - startTime; // store elapsed time
elapsedMinutes = (elapsedTime / 60000L); // divide by 60000 to convert to minutes - then cast to an int to print
elapsedSeconds = (elapsedTime / 1000L); // divide by 1000 to convert to seconds - then cast to an int to print
elapsedFrames = (elapsedTime / interval); // divide by 40 to convert to 1/25 of a second - then cast to an int to print
fractional = (int)(elapsedFrames % frameRate);// use modulo operator to get fractional part of 25 Frames
fractionalSecs = (int)(elapsedSeconds % 60L); // use modulo operator to get fractional part of 60 Seconds
fractionalMins = (int)(elapsedMinutes % 60L); // use modulo operator to get fractional part of 60 Minutes
lcd.clear(); // clear the LDC
if (fractionalMins < 10){ // pad in leading zeros
lcd.print("0"); // add a zero
}
lcd.print(itoa(fractionalMins, buf, 10)); // convert the int to a string and print a fractional part of 60 Minutes to the LCD
lcd.print(":"); //print a colan.
if (fractionalSecs < 10){ // pad in leading zeros
lcd.print("0"); // add a zero
}
lcd.print(itoa(fractionalSecs, buf, 10)); // convert the int to a string and print a fractional part of 60 Seconds to the LCD
lcd.print(":"); //print a colan.
if (fractional < 10){ // pad in leading zeros
lcd.print("0"); // add a zero
}
lcd.print(itoa((fractional), buf, 10)); // convert the int to a string and print a fractional part of 25 Frames to the LCD
}
}
}