I have been working on a new sketch. In my older sketches, I was able to figure out how to create a "multiple tasks" using one time base.
But this new sketch I am having trouble with.
Here is my loop code:
void loop() {
scroll(msg[msgChoice]); // scrolling message on an HT16K33 led matrix
currentTime = millis(); // time base
updateLedState(); // this is used for switching LEDs
switchLeds(); // This is just turning LEDs on and off
msgDecision(); // This is used to watch the status of a switch
}
The breakdown. each line is a sub function that gets called.
I have tested the LED switching with other sketches. It works fine. But here is my trouble. When I added the LED parts to the loop, it is not working. I can tell the "delay(msgInterval)" is what is part of the issue. The loop is in hold until it releases. By then the LEDs have gotten all screwed up.
@vader7071
1)
Please change the quote tags in the post to code tags. So we don't have to try to translate smilies and we don't have to read italics.
2)
Please post complete code. If it's too big, either attach or split over two or more posts.
And for the problem, I think that you need to get rid of delay completely.
PS
Re-reading your post, I think that you already figured that out. In which case you should get rid of the outer for loop in your scroll function.
void scroll(char* text)
{
static int scrollPositions = 0;
// when starting a new scroll, get the length
if(scrollPositions == 0)
{
scrollPositions = (strlen(text) * 8) - 32;
}
static int scrollCount = 8 * NUM_MATRICES;
static unsigned long scrollStart;
// if it's time
if (scrollStart - millis() >= msgInterval)
{
// scroll one position
for (uint8_t m = 0; m < NUM_MATRICES; m++)
{
matrix[m].clear();
matrix[m].setCursor((x - (m * 8)), 0);
matrix[m].print(text);
matrix[m].writeDisplay();
}
// restart timing
scrollStart = millis();
// one move completed
scrollCount--;
}
// if scroll completed
if (scrollCount == 0)
{
// reset for next scroll
scrollPositions = 0;
}
}
I have fixed the math syntax (no more addition, now using subtraction)
AND, I have attached the whole sketch.
I have not had a chance to try the "delay" fix yet. If I am able to today during lunch I will, otherwise, it will be tonight.
I guess what is messing me up is I am using a sketch for a MAX7219 as a guide and this sketch is just a wee bit different. But with y'alls help I think I will have this fixed.
Yeah, I was trying to fix that. I didn't use the code block thinking it was just one line, no real need to put the big code block in. OH BOY was I wrong. And then trying to edit it to fix it, the board said I had posted too many times in 5 minutes and had to be put in the corner in a time out.
Hmmmm....I tried the code. It compiled, but did not give the desired results.
The scroll starts, but locks up. Also, the adding LEDs do not work.
I know this like comparing apples to VW beetles, but I have attached the sketch am working on, and a sketch that works. Only trouble is, the working sketch is for the MAX7219 chips.
I am hoping someone else can see what I can't. I'm starting to get crosseyed.
Guys, thank you for your help! I know it may not seem like it, but y'all were a great help figuring this out. Once I realized my LED timing wasn't critical I was able to figure out my step counter.
I attached my final version if you want to look at it.