I''ll make sure I use them as boolean variables. The count 230 is merely an example to check whether the code works well or not. Actual count is a 5 digit number which will be taken as an input from the user via a 4x4 matrix keypad, which is I am going to implement next.
I have one more doubt. If here I change: if (currentMillis - prevMillis >= 1000) to may be 100 ms or anything else will I have to make change in the following statement as well.
A byte is not a boolean. Same size, same range of values, but there is a type called boolean for a reason.
unsigned long currentMillis = millis();
If you decide that you need finer resolution, and need to use micros(), you look pretty silly assigning the value returned by micros() to currentMillis. It is easy to see, then, that Millis is NOT necessary in the name. Something meaningful, like now, would be a better name.
if (countDoneFlag == false) {
A real programmer never uses == true or == false in an if statement.
if (!countDoneFlag)
{
timecheck = millis();//millis should be around 10k at this point
Does that comment add any value? What happens when you change interval, and it no longer takes 10 seconds to get to this point? Are you going to change the useless comment?
It is not necessary to supply an initial value for an array that you are going to step on immediately.
If you decide to count down for 20000 milliseconds, this statement will print "PulseCount:19999" (or some 5 digit number) the first time this statement is executed. Wouldn't "PulseCount: 19999" be better?
It is not necessary to supply an initial value for an array that you are going to step on immediately.
If you decide to count down for 20000 milliseconds, this statement will print "PulseCount:19999" (or some 5 digit number) the first time this statement is executed. Wouldn't "PulseCount: 19999" be better?
@PaulS:
Count the characters again. Also keep in mind what kind of display is being used.
Thanks PaulS for helping with all the corrections.
void loop() {
static bool countDoneFlag;
static bool doOneTime;
unsigned long now = millis();
static long timecheck;
if (now - prevMillis >= interval) {
if (!countDoneFlag) {
count--;
}
prevMillis += interval;
}
if (count == 0) {
if (!doOneTime) {
timecheck = millis();//millis should be around 10k at this point
lcd.clear();
doOneTime = 1;
}