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++;
}
}
}
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.
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.
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()