Go Down

Topic: Countdown stop watch (Read 1 time) previous topic - next topic

dhenry

Code: [Select]
  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() 


Looks like your code follows the interrupt approach I explained earlier. That's good.

Code: [Select]

void drawSecond(int second)
{
  switch(second)
  {
  case 0:
    dmd.drawString( 7,0, "00", 2, GRAPHICS_NORMAL );
    break;
  case 1:
    dmd.drawString( 8,0, "01", 2, GRAPHICS_NORMAL );
    break;


I don't quite understand the drawString function but it looks to be converting second into a string, with leading zero.

That's can be easily done:

Code: [Select]

unsigned char vBuffer[3]; //2 byte buffer


...
   //convert second to a string with leading zero
   //second assumed to be [0,99]
   vBuffer[1]='0'+(second % 10);
   vBuffer[0]='0'+(second /10);
   dmd.drawString(7, vBuffer, 2, NORMAL_GRAPHICS);


This would be considerably simpler.

PeterH


This would be considerably simpler.


Don't forget to null-terminate the string you just created.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up