Can you give me xample...to my sketch that I made

Oniduino:
My first generic stopwatch with 10 memory split
Are you who made it? And you who wrote the firmware? So you have a code to store the time splits to the memory. The code doesn't depend on type of the display, you can use the code from that stopwatch to the new one
Haha..Im not pro..Im not made it
You code is not suitable for the stopwatch.
Stopwatch must not use delay()
functions.
Again, are you call the Result()
from the function itself?

void Result(){ sprintf(lineBuff,"%02d:%02d:%02d",Minutes,Seconds,Cents); dmd.selectFont(Mono5x7); dmd.drawString( 1,2,lineBuff,strlen(lineBuff),GRAPHICS_NORMAL); Result(); }
this is an infinite recursion which will cause the program to hang.

Im not made it
So I don't understand, what you meant:

I have adapted a sketch for a stopwatch using an 16 x 2 LCD display
I try to analyze the sketch and try it for dot matrix displays

You code is not suitable for the stopwatch.
Stopwatch must not usedelay()
functions.Again, are you call the
Result()
from the function itself?Oniduino:
void Result(){ sprintf(lineBuff,"%02d:%02d:%02d",Minutes,Seconds,Cents); dmd.selectFont(Mono5x7); dmd.drawString( 1,2,lineBuff,strlen(lineBuff),GRAPHICS_NORMAL); Result(); }
this is an infinite recursion which will cause the program to hang.
Stay in Result() until I push reset
Reset on board arduino

Stay in Result() until I push reset
Did you try it?
This code won't "stay in...", it will hang the board almost immediately.
If you want to stay in the function - use infinite while
loop:
while (1);
Do not use recursion if you don't understand it.

Its work normali
No, it is impossible.
Perhaps you didn't try to run the code to the second lap.
Do not use recursion if you don't understand it.
#include <Wire.h>
#include <SPI.h> //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h> //Library DMD yang menyediakan fungsi penampilan teks, gambar dsb
#include <TimerOne.h> //Library peripheral Timer1 untuk menjalankan prosedur pindai panel DMD
#include <Time.h> //Library waktu yang menyediakan tipe data, struktur, dan obyek waktu
#include "Mono5x7.h"
#define DISPLAY_COLUMN_COUNT 3
#define DISPLAY_ROW_COUNT 2
#define PIXELS_PER_COLUMN 32
#define PIXELS_PER_ROW 16
DMD dmd(DISPLAY_COLUMN_COUNT, DISPLAY_ROW_COUNT);
unsigned char show = 0;
char lineBuff[20];
char lineBuff2[20];
int lineA;
int Start;
int minutes;
int seconds;
int cents;
long start_time = 0;
void ScanDMD()
{
dmd.scanDisplayBySPI();
}
void setup(void)
{
pinMode(2,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
pinMode(4,INPUT_PULLUP);
dmd.clearScreen( true ); //true is normal (all pixels off), false is negative (all pixels on)
Serial.begin(9600);
//initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
Timer1.initialize( 1000 ); //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
Timer1.attachInterrupt( ScanDMD ); //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
//clear/init the DMD pixels held in RAM
dmd.clearScreen( true );
}
void loop()
{
lineA = digitalRead(2);
if((lineA == 0)&&(Start == 0)){
delay(200);
Start = 1;
start_time = millis();
}
Chronometer();
Pause();
Laptime();
}
void Chronometer(void){
if(Start == 1){
minutes = (millis() - start_time) / 60000;
seconds = ((millis() - start_time) / 1000) % 60;
cents = ((millis() - start_time) / 10) % 100;
}
//===========================================================================
sprintf(lineBuff, "%02d:%02d.%02d",minutes,seconds,cents);
dmd.selectFont(Mono5x7);
dmd.drawString( 1, 2, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);
//===========================================================================
}
void Pause(void){
if(digitalRead(4) == HIGH)
return;
else if (digitalRead(4) == LOW){
while(digitalRead(2) == HIGH) {
if (digitalRead(3) == LOW)
Laptime();
}
}
}
void Split(void){
if(digitalRead(3) == HIGH)
return;
else if (digitalRead(3) == LOW){
Laptime();
}
}
void Laptime(void){
if(digitalRead(3) == HIGH)
return;
else if (digitalRead(3) == LOW){
sprintf(lineBuff, "%02d:%02d.%02d",minutes,seconds,cents);
dmd.selectFont(Mono5x7);
dmd.drawString( 1, 10, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);
while(digitalRead(3) == LOW) {};
}
}

how do you add a split lap, second, third and so on?
In the Pause()
procedure, there is no point in calling Laptime()
in a loop:

while(digitalRead(2) == HIGH) { if (digitalRead(3) == LOW) Laptime(); }
the time inside this procedure is not updated, so the stopwatch display will stand still. And if so, it means that it is enough to display the data on the screen once
Yes, that's true. Even the time doesn't stop properly when paused, only the display stops
What should I do?

Even the time doesn't stop properly when paused, only the display stops
It is because the millis() doesn't stop when you enter to the Pause()
function
how do i pause of millis?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.