Timer routine help

2560 Mega connected to a motor controller, brushed motor, 16x2 LCD.

I've got a menu built with a settings option where you can select Increase Time or Decrease Time. Time defaults to 1 minute. Once the time is set I want to be able to go to another menu and start the motor routine that will run for that specified amount of time.

I start off with a global variable: int time_minutes = 1;

when the user selects that from the menu it runs the following:

void menu_increaseTime() { lcd.clear(); lcd.setCursor(0,0); time_minutes = time_minutes + 1; lcd.print(time_minutes); lcd.print(" minutes"); }

void menu_decreaseTime() { lcd.clear(); lcd.setCursor(0,0); if (time_minutes > 0) time_minutes = time_minutes - 1; lcd.print(time_minutes); lcd.print(" minutes");

}

the first time I select it displays 10 minutes, then 20 minutes, the 29, 39, 48, 57, 65, etc. decrease shows 56, 48, 39, 30, 22, 14, 7, then 0

It should be increasing or decreasing the amount of time by increments of 1. Any ideas?

Second I need to be able to run my motor controller routine for the amount of time specified in the time_minutes variable. Any suggestions for a routine to do that?

Are you debouncing your buttons?

I need to be able to run my motor controller routine for the amount of time specified in the time_minutes variable. Any suggestions for a routine to do that?

This is a bare-bones solution. Nothing fancy.

digitalWrite(motorpin, HIGH);
delay(time_minutes*60000);
digitalWrite(motorpin, LOW);

What does debouncing the buttons mean? I’m using a 16x2 LCD with built in buttons. They output an analog signal on a single analog input and then based on the value returned a subroutine determines the button selected. It’s not perfect but seems to work ok.

Any idea why the value of the time_minutes variable doesn’t increase by 1 each time I run it?

Any idea why the value of the time_minutes variable doesn't increase by 1 each time I run it?

Yes

http://lmgtfy.com/?q=arduino+debounce

Any idea why the value of the time_minutes variable doesn't increase by 1 each time I run it?

Could be an artifact of the LCD display. Use Serial.print() to print a message each time the switch is pressed, and to output the time_minutes value. See if they match, or not, in the Serial Monitor.