Hey guys,
Just to start off, I am a complete noob and just started using a simulator while I waiting for my Arduino starter kit to arrive. I would like your advice on how to best set up my code.
I am trying to get 6ish cases to display on an LCD screen, each incrementing a counter depending on the lcd.print (millis() / X),
However with the current code, the cases seem to be running and are displayed simultaneously which is not what I want.
I would love your advice on how to set it up so that each randomly selected case runs after each other, having been been displayed for a certain time (ex. 30-60 seconds). I have tried to use the millis() function to decide, and even tried with:
startMillis;
and
currentMillis;
But cannot seem to get this to work so deleted them pending some more info/guidance so that I understand what I am doing.
Ideally, the loop would stop after around 10-20mins, depending on how much is incremented to the screen (ex. 15,000). The idea is that each random case provides a higher/lower count on the screen depending on the milis()/X displayed, so the exact timing is hard to calculate. Any advice on how to implement this would also be much appreciated.
Apologies for the simple questions, but coding has never been my strong suit.
Below is the current code:
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 1000;
void setup() {
}
void loop()
{
byte randNum = random(0, 4);
switch (randNum)
{
case 1:
{
lcd.begin(16, 2);
lcd.print("Test1!");
lcd.setCursor(0, 1);
lcd.print (millis() / 500);
currentMillis = millis();
delay(250);
break;
}
case 2:
{
lcd.begin(16, 2);
lcd.print("Test2!");
lcd.setCursor(0, 1);
lcd.print (millis() / 500);
delay(250);
break;
}
case 3:
{
lcd.begin(16, 2);
lcd.print("Test3!");
lcd.setCursor(0, 1);
lcd.print (millis() / 500);
delay(250);
break;
}
}
}