Case statements for an RGB LED Matrix

Hey Guys,

Thanks for having a look at my post.

I'm fairly new to Arduino and am very average at coding – so please forgive me if my code is horrendously structured or way longer than it needs to be! A Uni assignment has required me to delve into this field and give it a crack!

I’ve had a fair bit of success using YouTube, sample code and referring to other questions posted on the Arduino Forums to get me this far, however can’t seem to solve this particular problem.

I’ve developed a case statement which I want to use to automatically cycle through three different screens/displays – a stopwatch, a clock and a counter. When I open the serial monitor it communicates that the case is switch every 10 seconds between the three screens. But on the actual, physical matrix display it only shows the stopwatch with a flash of what I want to be displayed next only appearing for less than a second.

  //Case statements for switching between Counter, Stopwatch and Clock

  if(stopWatchSecs % switchInterval == 0 && !matrixSwitched){
    matrixSwitched = true;
    Serial.println("Switched");

    matrixSwitch++;
    if(matrixSwitch == 3)
    matrixSwitch = 0;

    switch(matrixSwitch){

      case 0:
      Serial.println("Case 0");
      matrixFormat();
      break;

      case 1:
      Serial.println("Case 1");
      timeClockCode();
      break;

      case 2:
      Serial.println("Case 2");
      lapCounterCode();
      break;
    }
  }

  if(stopWatchSecs % switchInterval == 1 && matrixSwitched){
    matrixSwitched = false;
  }
}

Oh and I’m currently trying to merge all my different functions together (the clock, stopwatch and counter) so all of that individual code won’t be in the file.

Would love your help and feedback! I’ve attached the code below.

THart_SwitchMatrixIssue.ino (4.91 KB)

How fast can you read the display, because it's only going to be there for a few microseconds. Perhaps a delay() would help. Also, it's almost never good to have closely-named variables (e.g., matrixSwitched, matrixSwitch). Finally, please read Nick Gammon's post at the top for the Forum on how to use code tags for posting source code.

Hey econjack.

Thanks for the reply. Ideally I wanted it to switch between each display each 5-10 seconds.

I have trialled it with delays in the past, but that freezes the seconds and milliseconds - kind of defeats the purpose of having a stopwatch or clock.

Thanks