Hi every one,
I have a Chronograph proyect to play with my kids, running inside our house like a circuit, so I want to build a Arduino Chonograph, I have a 8 digit display, as cool as the one in the car of Return to the future, and it works well on the start, I have to press it to maintain the timer on stop and then once I touch the arrival button it keeps running when I stop pressing, really frustrating because I cannot see the end time, I need the timer to stop once I touch the button, one touch not keep pressing.
This is the code, may be someone can help me Please
/*
#######################################################
Chronometer with hundred of a second.
Works> When Pin 3 gets High, starts counting, as if you left your feet from the button
#######################################################
MAX7219 connections:
MAX7219 chipKIT Uno32
VCC ---------------> 5.0V
DIN ---------------> Pin 12
CLK ---------------> Pin 11
LOAD ---------------> Pin 10
GND ---------------> GND
drukknop op D2 met plus op 3.3 volt
#######################################################
Start/Stop tact switch is connected to INT0 (Pin D3) pin.
*/
#include "LedControl.h"
// Pin 7 to Data In, 6 to Clk, 5 to LOAD
LedControl lc = LedControl(12, 11, 10, 1);
int fsec, sec, minute, reminuto, i, Start;
const int boton = 8;
int val = 0;
int old_val = 0;
int state = 0;
unsigned long previousMillis = 0;
unsigned long interval = 6;
int parador = 1;
void setup()
{
// the zero refers to the MAX7219 number, it is zero for 1 chip
//pinMode(4,INPUT);// Creamos un botón para que reciba la señal de parada
lc.shutdown(0, false); // turn off power saving, enables display
lc.setIntensity(0, 12); // sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen
pinMode(boton, INPUT);
fsec = 0;
sec = 0;
minute = 0;
reminuto = 0;
Start = LOW;
lc.setChar(0, 2, '.', false);
lc.setChar(0, 5, '.', false);
Disp_Data();
parador = 1;
int val;
//pinMode(boton,INPUT);
// When the pin 3 gets High starts
attachInterrupt(1, Button_Pressed, HIGH);
// attachInterrupt(2, pulsador, HIGH);
}
void loop()
{
pulsador();//checks if you are pressing to stop
comprobador();// checks if you should keep running
if (Start == 1) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
fsec = fsec + 10 * parador;
if (fsec == 100) {
fsec = 0;
sec = sec + 1;
if (sec == 100) {
sec = 0;
minute = minute + 1;
if (minute == 60) minute = 0;
reminuto = reminuto + 1;
//Serial.print("reminuto: ");
//Serial.println(reminuto);
}
}
Disp_Data();
//pulsador();
}
}
}
void Button_Pressed() {
if (Start == 1) {
Start = 0;
}
else if (Start == 0) {
Start = 1;
}
}
void pulsador() {
val = digitalRead(boton);
if ((val == HIGH) && (old_val == LOW)) {
state = 1 - state;
}
old_val = val;
}
void comprobador() {
if (state == 1) {
parador = 1;
}
else {
parador = 0;
}
}
void Disp_Data() {
int ones, tens;
// First display fsec
ones = fsec % 10; // Dont really know what its showing..
tens = (fsec / 10) % 10; //showing hundreds
lc.setDigit(0, 0, (byte)tens, false); //showing hundreds
lc.setDigit(0, 7, (byte)ones, false); //no idea whats this
// Now display sec
ones = sec % 10; //tenths of a second
tens = (sec / 10) % 10;
lc.setDigit(0, 3, (byte)tens, false);
lc.setDigit(0, 1, (byte)ones, false);
// Next display mm
ones = minute % 6; //turns into a minute
tens = (reminuto / 6) % 6;
lc.setDigit(0, 6, (byte)tens, false); //shows 2 minutes
lc.setDigit(0, 4, (byte)ones, false); // shows seconds
}