Hi all! This is my first time on this forum and just so you know I'm a beguiner with Arduino.
I would like to make a "laser cutter status" for my machine that includes a chronograph for the specific "cut" and a "total work time". I'm having a problem showing the time elapsed for the specific cut. At the moment I can do so, but just when the cut is finish and not while the machine is working. This is were I think my code is not wright:
void loop(void)
{
nexLoop(nex_listen_list);
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
timestart= millis(); //- Start chronograph time
}
else {
displaycrono(); // Display elapsed time
writetoLong(); //- save to EEPROM
}
delay(50);
}
lastButtonState = buttonState;
}
void displaycrono(){
timeend = millis() - timestart;
hours=int(timeend/3600000);
over=timeend%3600000;
minutes=int(over/60000);
over=over%60000;
seconds=int(over/1000);
memset(buffer, 0, sizeof(buffer));
memset(buffer_temp, 0, sizeof(buffer_temp));
itoa(seconds, buffer_temp, 10);
if (seconds < 10)
{
strcat(buffer, "0");
}
strcat(buffer, buffer_temp);
if (strcmp(buffer_second, buffer))
{
csegundos.setText(buffer);
}
memset(buffer, 0, sizeof(buffer));
memset(buffer_temp, 0, sizeof(buffer_temp));
itoa(minutes, buffer_temp, 10);
if (minutes < 10)
{
strcat(buffer, "0");
}
strcat(buffer, buffer_temp);
if (strcmp(buffer_minutos, buffer))
{
cminutos.setText(buffer);
}
memset(buffer, 0, sizeof(buffer));
memset(buffer_temp, 0, sizeof(buffer_temp));
itoa(hours, buffer_temp, 10);
if (hours < 10)
{
strcat(buffer, "0");
}
strcat(buffer, buffer_temp);
if (strcmp(buffer_horas, buffer))
{
choras.setText(buffer);
}
}
When the machine start the cut, I start the millis() funcion, and when the cut stop I Display the chronograph and update the total time to the EEPROM. However if I try to "Displaycrono" outside the ""if" statment but inside de "loop", the program freezes showing the elapsed time, and don´t do anything else... did I explain myself wright? Can anyone give-me a little help? Thanks