This is my code for timing specific functions and displaying to LCD.
i chose float so it displays seconds with 2 decimal places. It gives me 7.02 seconds for function 1 and 3.07 seconds for function 2. i believe it to be accurate.
Can i improve upon this code? Do you see any problems with it?
unsigned char drinkSelection = 0;
void setup() {
Serial.begin(9600); //Open Serial with baud rate 9600
lcd.begin(0x27,16, 2); //Start lcd (address, rows, columns)
void adiosSucka()
{
float oldMillis = millis();
float time = 0;
Serial.println("You have Chosen Adios Sucka"); //Greetings
Serial.println(" ");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("You have chosen");
lcd.setCursor(0,1);
lcd.print("Adios Sucka");
delay(250);
yAxis->step(1050, BACKWARD, DOUBLE);delay(5000);
time = millis() - oldMillis;
drinkSelection=0; //Reset Variables
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Drink made in");
lcd.setCursor(0,1);
lcd.print(time/1000);
lcd.setCursor(2,1);
lcd.print("seconds");
delay(3000);
lcd.clear();
lcd.setCursor(1,0); //Restart Welcome
lcd.print("Select a drink");
time=0;
}
//(2) Alpine Lemonade [(30mL Vodka, Gin, Rum) (60mL Cranberry, Lemonade)]
void alpineLemonade()
{
float oldMillis = millis();
float time = 0;
Serial.println("You have chosen Alpine Lemonade");
Serial.println(" ");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("You have chosen");
lcd.setCursor(0,1);
lcd.print("Alpine Lemonade");
delay(3000);
time = millis() - oldMillis;
drinkSelection=0; //Reset Variables
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Drink made in");
lcd.setCursor(0,1);
lcd.print(time/1000);
lcd.setCursor(2,1);
lcd.print("seconds");
delay(3000);
lcd.clear();
lcd.setCursor(1,0); //Restart Welcome
lcd.print("Select a drink");
time=0;
}