Here's what I want my code to do: This is part of a tea infusing project that would automate the steeping of tea, part of this is initially having a selection of either Black/Herbal tea or White/Green tea, this will then set off several other factors down the timeline. I want my LCD screen to display and scroll "Please select a tea" while still being able to take in pushbutton input.
I've been doing this all day, and I've tried several things. I firstly tried using a normal delay function so my text could scroll properly, but the problem with that is that it halts all the code and doesn't allow for any other input, so I quickly found millis() was likely what I needed to use. However, when I try to apply it to this specific example, it just scrolls all my text extremely quickly through the LCD. Perhaps I'm being stupid and ignoring something obvious, but please let me know.
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
const int black_herbal_osb = 2;
int black_select;
//Timing
unsigned long prev_millis;
unsigned long current_millis;
const unsigned long LCD_delay = 500;
void setup() {
//Tea selection buttons
pinMode(black_herbal_osb, INPUT);
//LCD screen setup
lcd.init();
lcd.backlight();
}
void loop() {
lcd.autoscroll();
lcd.setCursor(16, 0);
lcd.print("Please");
current_millis = millis();
black_select = digitalRead(black_herbal_osb);
if (black_select != HIGH) {
if (current_millis - prev_millis >= LCD_delay) {
lcd.print(" select ");
prev_millis = current_millis;
}
if (current_millis - prev_millis >= LCD_delay * 2) {
lcd.print("a ");
prev_millis = current_millis;
}
if (current_millis - prev_millis >= LCD_delay * 3) {
lcd.print("tea ");
prev_millis = current_millis;
}
}
else if (black_select == HIGH) {
lcd.clear();
lcd.autoscroll();
lcd.setCursor(16, 0);
lcd.print("Black/Herbal ");
delay(500);
lcd.print("tea ");
delay(500);
lcd.print("selected");
delay(2000);
lcd.noAutoscroll();
lcd.clear();
}
}