multitasking

hi
i am working on a project where in i need to display a timer counter for 60 sec in left side of the display, and in the other half of the display i need to display a scrolling message. the timer counter will run continuously irrespective of message displayed in the other half of the display.

after 60 sec i need to clear the entire display.

i am using LED P10 32*16 display, with red color.
i am using DMD2 library to do the above task.

i am able to do the task of displaying the counter and message respectively but the counter gets delayed due to the long message.

#include <SPI.h>
#include <DMD2.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>
#include <fonts/Droid_Sans_24.h>
#include <fonts/Droid_Sans_16.h>
// Set Width to the number of displays wide you have
const int WIDTH = 1;
const int COUNTDOWN_FROM = 0;
int counter = COUNTDOWN_FROM;


const uint8_t *FONT = SystemFont5x7;
const uint8_t *FONT2 = SystemFont5x7;

const char *MESSAGE = "GOA  ";

SoftDMD dmd(WIDTH,1);  // DMD controls the entire display
DMD_TextBox box(dmd, 0, 1);
DMD_TextBox box1(dmd,11,1);  // "box" provides a text box to automatically write to/scroll the display

long previousMillis = 0;        // will store last time box was updated
long interval = 1000;

unsigned long previousMillis2 = 0;
long interval2 = 1000;

void scroll();
void run_counter();
// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(9600);
  dmd.setBrightness(255);
  //dmd.selectFont(FONT);
  dmd.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
    unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    
    previousMillis = currentMillis;   

 
    if (counter <60)
    {
      dmd.selectFont(FONT);
      box.print(counter);
      box.println(F(""));
      counter++;
    }
    else
    {
      box1.clear();
      counter = 0;
      box.print(counter);
      // box.println(F(""));
      dmd.clearScreen();
    } 
    
  }

  if(currentMillis - previousMillis2 >= interval2)
  {
    previousMillis2 = currentMillis;  // Remember the time
     dmd.selectFont(FONT2);
     const char *next = MESSAGE;
     while(*next) {
     Serial.print(*next);
     box1.print(*next);
     delay(500);
     next++;
     }
  }
    
}

please help

     delay(500);

Don't do that then.

You may have to break this loop into a third timer with a 500ms interval.

how to break it into 500ms??

gourish:
how to break it into 500ms??

"Delay" pauses your program. Take a look at this
https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

The demo Several Things at a Time is an extended example of BWoD and illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

...R

ok i removed the delay but then my message is scrolling to fast.

gourish:
ok i removed the delay but then my message is scrolling to fast.

In that case check the time using the millis() function. You can slow down the message output without actually stopping your program,

In that case check the time using the millis() function. You can slow down the message output without actually stopping your program,

i tried using millis() but the result is the same.

i think i need to change the way i am scrolling the message.

dmd.selectFont(FONT2);
const char *next = MESSAGE;
while(*next) {
Serial.print(*next);
box1.print(*next);
delay(500);
next++;
}

is there any other method in which i can scroll the message the way i want?

gourish:
i tried using millis() but the result is the same.

i think i need to change the way i am scrolling the message.
is there any other method in which i can scroll the message the way i want?

See response #4 by Robin2, follow the link and read it thoroughly.

i read it but it gave me idea on how to do this multitasking with led and servo that is fine.

but the same thing i am not able to do with the scrolling message.

and i didn't find anyone doing this stuff like count up timer with a scrolling message, were the message will have its own speed and counter will run as a clock.

There is not much difference between having an LED go on or off, or moving a message by one character.

gourish:
i read it but it gave me idea on how to do this multitasking with led and servo that is fine.

but the same thing i am not able to do with the scrolling message.

and i didn't find anyone doing this stuff like count up timer with a scrolling message, were the message will have its own speed and counter will run as a clock.

In summary using the BlinkWithoutDelay principle

start of loop()
  if the LED state change state period has passed
    change the LED state
    save the time
  end if

  if the message scrolling period has passed
    scroll the message
    save the time
  end if
end of loop()

start of loop()
if the LED state change state period has passed
change the LED state
save the time
end if

if the message scrolling period has passed
scroll the message
save the time
end if
end of loop()

after making this changes i am only able to print the counter the scrolling message is not printing.

char MESSAGE = "GOA  ";

SoftDMD dmd(WIDTH,1);  // DMD controls the entire display
DMD_TextBox box(dmd, 0, 1);
DMD_TextBox box1(dmd,11,1);  // "box" provides a text box to automatically write to/scroll the display

long previousMillis = 0;        // will store last time box was updated
long interval = 1000;

unsigned long previousMillis2 = 0;
long interval2 = 1000;

void setup() {
  Serial.begin(9600);
  dmd.setBrightness(255);
  //dmd.selectFont(FONT);
  dmd.begin();
  
}

void loop() {
ss  unsigned long currentMillis = millis();
     char *next = MESSAGE;
 if((counter <60)&&currentMillis - previousMillis > interval) {
      dmd.selectFont(FONT);
      box.print(counter);
      box.println(F(""));
      counter++;
      previousMillis = currentMillis;    
  }
 if((counter <60)&&(currentMillis - previousMillis2 > interval2))
    {
      dmd.selectFont(FONT);
      Serial.print(*next);
      box1.print(*next);
      *next++;
       previousMillis2 = currentMillis;  
     }
     
 if(counter == 60)
      {
         dmd.clearScreen();
      }
}

If you comment out the counter code does the scrolling message work ?

Before your IF statements print the variables used in the IF.
You will then see why the IF does or does not do what you are expecting.

this method is not helping me m trying from 4 hours now i came up with new method it is helpful but the message scrolls too fast.

#include <mthread.h>
#include <SPI.h>
#include <DMD2.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>
#include <fonts/Droid_Sans_24.h>
#include <fonts/Droid_Sans_16.h>
// Set Width to the number of displays wide you have
const int WIDTH = 1;
const int COUNTDOWN_FROM = 0;
int counter = COUNTDOWN_FROM;


const uint8_t *FONT = SystemFont5x7;
const uint8_t *FONT2 = SystemFont5x7;

//int len = strlen(MESSAGE);
SoftDMD dmd(WIDTH,1);  // DMD controls the entire display
DMD_TextBox box(dmd, 0, 1);
DMD_TextBox box1(dmd,11,1);  // "box" provides a text box to automatically write to/scroll the display
// Our custom Thread:
class FooThread : public Thread
{
public:
    FooThread(int id);
protected:
    bool loop();
private:
    int id;
    const char MESSAGE = "I am in VASCO DA GAMA, GOA";
};

FooThread::FooThread(int id)
{
    this->id = id;
    
}

bool FooThread::loop()
{

    // Die if requested:
    if(kill_flag)
        return false;
        
    // Print the status message:
    Serial.println(id);
    if((id==1)&&(counter <10))
    {   
       Serial.println(counter);
       dmd.selectFont(FONT);
       box.print(counter);
       box.println(F(""));
       counter++;
       previousMillis = currentMillis;    
    }
    else if((id ==3)&&(counter <10))
    {
     dmd.selectFont(FONT2);
     const char *next = "MESSAGE TO THE TRAVELER";
     while(*next) {
     Serial.print(*next);
     box1.print(*next);
     sleep(3);
     next++;
     }
     sleep_milli(100);
    }
    else if (counter >=10)
    {
      dmd.clearScreen();
      kill(true);
    }
    // Sleep for one second:
    sleep(1);// sleep for one second
    return true;

}

void setup()
{ 
     main_thread_list->add_thread(new FooThread(3));
     main_thread_list->add_thread(new FooThread(1));
     
     Serial.begin(9600);
     delay(1000);
     dmd.begin();
}

gourish:
m trying from 4 hours now

That's not very long ...

...R

this method is not helping me

There should be no need to use yet another library to do something fundamentally simple such as timing 2 events independently

Can you please answer the question that I posed in reply #13 with respect to your code in reply #12

I see that you declare MESSAGE as a char

char MESSAGE = "GOA  ";

How many characters can a simple char variable hold ?

try reverting everything you did, then use the neotimer library
link

search neotimer on libraries and install it

devcoder:
try reverting everything you did, then use the neotimer library

Why not just use millis() ?

...R