(beginner) dmd display 2 digits instead of character in stopwatch.

hi all
before my question
yes i am very new to this so the coding is probably a dogs breakfast. i am doing this project for a friend for for a sports event coming up.

so my problem is probably simple. The code does exactly what i want aside from the fact that when the timing code gets to 10 the drawchar puts in the character corresponding to that number. Therefore the although the stopwatch works the display shows characters instead of 2 digit numbers.

does anyone have an easy fix for this

cheers all for your help

stopwatcch1_works.ino (4.35 KB)

#include <SPI.h>        //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>        //
#include <TimerOne.h>   //
#include <Arial_Black_16.h>
#define StopButton 4                 // button on pin 4
#define StartButton 2                 // button on pin 2

int buttonStateStart;                    // variable to store button state
int lastButtonStateStart;                // variable to store last button state
int buttonStateStop;                    // variable to store button state
int lastButtonStateStop;                // variable to store last button state
int fractional;
int fractionalOld;
byte StopWatchRun = LOW;
unsigned long start, finished, elapsed;

//Fire up the DMD library as dmd
DMD dmd(1,1);
unsigned int ui;
int fontNr=0;
int minute=0;
int second=0;
byte secOver = HIGH;
int i=0;


void ScanDMD()
{ 
  dmd.scanDisplayBySPI();
}


void setup(void)
{ 
    Serial.begin(9600);
    
    pinMode(StartButton, INPUT); // the start button
    pinMode(StopButton, INPUT); // the stop button
    Serial.println("Press 1 for Start/reset, 2 for elapsed time");
   
   //initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
   Timer1.initialize( 5000 );           //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 );   //true is normal (all pixels off), false is negative (all pixels on)
   dmd.selectFont (Arial_Black_16);
}


void loop(void)
{
  buttonStateStart = digitalRead(StartButton);
  buttonStateStop = digitalRead(StopButton);
  
  if (buttonStateStart == LOW && lastButtonStateStart == HIGH)
    {
    start = millis();
    delay(5); // for debounce
    Serial.println("Started...");
    lastButtonStateStart = buttonStateStart; 
    StopWatchRun = HIGH;
    }
  else if (buttonStateStop == LOW && lastButtonStateStop ==HIGH)
    {
    finished = millis();
    delay(5); // for debounce
    displayResult();
    lastButtonStateStop = buttonStateStop; 
    StopWatchRun = LOW;
    }
  else
    {
     if (StopWatchRun == HIGH)
      {
       fractional = (int)(millis() % 1000L);
       if (fractional < fractionalOld)
        {
         finished = millis();
         displayResult();

           if (secOver == 1)
           {
            minute=minute--;
            second=60;
            secOver = 0;
           }
           second=second--; 
           ui = minute * 100 + second;   
           Blink(ui);
           if(second==0)
           {   
            secOver = 1;  
           }
        }   
      }
             
     lastButtonStateStart = buttonStateStart;
     lastButtonStateStop = buttonStateStop;
     fractionalOld = fractional;    
    }
}


void displayResult()
{
float h, m, s, ms;
unsigned long over;

  elapsed = finished - start;
  h = int(elapsed / 3600000);
  over = elapsed % 3600000;
  m = int(over / 60000);
  over = over % 60000;
  s = int(over / 1000);
  ms = over % 1000;
  Serial.print("Raw elapsed time: ");
  Serial.println(elapsed);
  Serial.print("Elapsed time: ");
  Serial.print(h, 0);
  Serial.print("h ");
  Serial.print(m, 0);
  Serial.print("m ");
  Serial.print(s, 0);
  Serial.print("s ");
  Serial.print(ms, 0);
  Serial.println("ms");
 
}


void Blink(unsigned int uiTime)
{
    if(i) 
     {
      ShowClockNumbers( uiTime, false );
      i = 0;
     }
     else
      {
       ShowClockNumbers( uiTime, true );
       i=1;
      }
}


void ShowClockNumbers( unsigned int uiTime, byte bColonOn )
{  
  int h, m, s, ms;
unsigned long over;

  elapsed = finished - start;
  h = int(elapsed / 3600000);
  over = elapsed % 3600000;
  m = int(over / 60000);
  over = over % 60000;
  s = int(over / 1000);
  ms = over % 1000;
   
   dmd.clearScreen(true);
 
  String str1;
     ShowClockNumbers;
     dmd.drawChar( 1, 1,'0'+s,  GRAPHICS_NORMAL );
 
     dmd.drawChar( 23, 1,'0'+ m,    GRAPHICS_NORMAL );   // tens
  
   if( bColonOn )
      dmd.drawChar( 19,  0, ':', GRAPHICS_OR     );   // clock colon overlay on
   else
      dmd.drawChar( 19,  0, ':', GRAPHICS_NOR    );   // clock colon overlay off
}

If the number is two digits, you will have to print twice.

  dmd.drawChar( 1, 1, '0' + s/10,  GRAPHICS_NORMAL )
  dmd.drawChar( 1, 1, '0' + s%10,  GRAPHICS_NORMAL );

I'm not familiar with you library, so not sure which parameter you need to change to print the second digit after the first one.

Question: what is or what do you think that the effect is of the second parameter in e.g.

  Serial.print(h, 0);

cheers mate much appreciated just had to add an extra value in for tens of seconds and reduce to time over on the seconds