Millisecond countdown using MsTimer2 or FlexiTimer

Dear All,

First of all, I am very new person with very limited background on Microcontroller programming.

I am, kindly, asking for advice, guide and / or program example.

I am currently build a millisecond countdown based on Arduino Uno R3 SMD with LCD and 4x4 keypad with LED that flashes when programmed time is reached.

To my understanding, MsTimer2 has 1 millisecond accuracy. It is possible to use this?

To be honest, I don't have any idea how to use and how to vary the timing parameter in order to make this countdown programmable / adjustable using keypad, simply by just enter the second.millisecond, say for 3.5second, I just enter 3.500 and to make it counting down.

Your attention and help is greatly appreciated.

Regards,
Donny

It is possible to use this?

Yes, but why? You know (or should) the number of milliseconds since the Arduino was reset when the countdown should start. You know (or should) the number of milliseconds since the Arduino was reset that have passed until now. Simple math will tell you how many milliseconds to go until the proper amount of time has elapsed.

PaulS:
Yes, but why? You know (or should) the number of milliseconds since the Arduino was reset when the countdown should start. You know (or should) the number of milliseconds since the Arduino was reset that have passed until now. Simple math will tell you how many milliseconds to go until the proper amount of time has elapsed.

Thank you very much for giving me the idea :slight_smile: Help me to better understand how it should work

I found a sketch sample from Arduino IDE, demonstrating simple LCD "Hello World" with millis at the botom row. I modified the code to work with I2C. Hereis the code

#include <LCD.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library


/*-----( Declare Constants )-----*/
/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 16 chars 2 line display
// A FEW use address 0x3F
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

/*-----( Declare Variables )-----*/
//NONE

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis());
}

I prefer to use millis() or even micros() to make a simple counter. I am thinking on how to make a programmable countdown counter: It works as simple as If I enter 10.500second (one and half second) it counts-down until zero then print "Stop" on the LCD.

To be honest, I have very little background on programming. I need help on how to "invert" the counting process.

To be honest, I have very little background on programming. I need help on how to "invert" the counting process.

I'm sorry. That is so trivial that I think you should be able to figure it out. If timeRemaining-- decreases the timeRemaining, surely you can guess what to do to timePassed to make it increase.

Why use those other libraries, instead of the built-in millis()? There's also micros() if you need more precision.

I think that should be fine for what you want to do...