Some Help Building char array for scoreboard

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
Kerl
Posts:15
Joined:Fri Dec 04, 2015 1:57 am
Some Help Building char array for scoreboard

Post by Kerl » Fri Dec 04, 2015 2:35 am

Hey All,

I'm building a Countdown timer for my scoreboard using a DMD and a Ardunio Uno R3. The code below compiles fine, but I'm having issues building char array instead of using.

Code: Select all

String minsTens, minsUnits, secsTens, secsUnits
The current code below is causing a reset.

Can someone help me rebuild the following code using a char array? Or is there some other way I should be going? I'm new with C and with Java I can usually identify array issues in compiling.

Thanks heaps!

Code: Select all

#include <SPI.h>
#include <DMD.h>
#include <TimerOne.h>
#include <TimedAction.h>
#include "SystemFont5x7.h"
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

String minsTens, minsUnits, secsTens, secsUnits;
int mins10, mins1, secs10, secs1;
int minutes, seconds;
int clockRunning = 0;

void clockUpdate();

TimedAction timer = TimedAction(1000,clockUpdate);

void setup() {
  
  timer.disable();
  minutes = 0; 
  seconds = 0;
  pinMode(2, OUTPUT);
  pinMode(A5, INPUT_PULLUP);
  pinMode(A4, INPUT_PULLUP);
  pinMode(A3, INPUT_PULLUP);
  
  Timer1.initialize( 4000 );           //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()
  dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)

  dmd.selectFont(SystemFont5x7);
  dmd.drawString(2,0,"TIME:",5,GRAPHICS_NORMAL);
  dmd.drawString(8,8,"SET",5,GRAPHICS_NORMAL);
  beep();
}

void loop() {

  if (clockRunning == 0) {
    if (digitalRead(A3) == 0) {
      mins10++; 
      delay(200); 
      if (mins10 > 9) mins10 = 0;
      minutes = mins10 * 10 + mins1;
      displayUpdate();
    }
    if (digitalRead(A4) == 0) {
      mins1++; 
      delay(200);
      if (mins1 > 9) mins1 = 0;
      minutes = mins10 * 10 + mins1;
      displayUpdate();
    }
  }
  if (digitalRead(A5) == 0) {
    beep();
    delay(200);
    if (clockRunning == 0) {
      timer.enable();
      clockRunning = 1;
    } else {
      clockRunning = 0;
      timer.disable();
      dmd.drawString(2,8," OFF ",5,GRAPHICS_NORMAL);
      delay(3000);
      displayUpdate();
    }
  }

  if (clockRunning == 1) timer.check();  
}

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

void clockUpdate() {
  seconds--;
  if (seconds < 0) { 
    seconds = 59;
    minutes--;
  }
  secs10 = seconds / 10;
  secs1 = seconds % 10;
  mins10 = minutes / 10;
  mins1 = minutes % 10;
  displayUpdate();

  if (minutes == 0 && seconds == 0) {
    dmd.clearScreen(true);
    dmd.drawString(5,0,"FULL",4,GRAPHICS_NORMAL);
    dmd.drawString(5,8,"TIME",4,GRAPHICS_NORMAL);
    timer.disable();
    digitalWrite(2, HIGH);
  }
}

void displayUpdate() {
  minsTens = (String)mins10;
  minsUnits = (String)mins1;
  secsTens = (String)secs10;
  secsUnits = (String)secs1;
  
  dmd.drawString(2,8,minsTens.c_str(),1,GRAPHICS_NORMAL);
  dmd.drawString(8,8,minsUnits.c_str(),1,GRAPHICS_NORMAL);
  dmd.drawString(14,8,":",1,GRAPHICS_NORMAL);
  dmd.drawString(19,8,secsTens.c_str(),1,GRAPHICS_NORMAL);
  dmd.drawString(25,8,secsUnits.c_str(),1,GRAPHICS_NORMAL);
}

void beep() {
  digitalWrite(2, HIGH);
  delay(30);
  digitalWrite(2, LOW);
}

User avatar
stryker
Posts:282
Joined:Sat Jan 14, 2012 2:44 pm

Re: Some Help Building char array for scoreboard

Post by stryker » Fri Dec 04, 2015 4:18 am

Hi

The examples for the DMD library show how you can store these values as integers and just calculate the characters to output at the time you need to display them. The clock is a good one to understand, and since you're only storing up to double digits of minutes you could have the entire countdown timer stored as a single count of seconds and calculate the digits to display from there rather than trying a character array etc.

99 minutes and 59 seconds (the max your display will show) is 5999 seconds, so easy to contain within a single integer counter (int maximum positive value is 32,767).

Hope this helps,
Geoff

Post Reply