Dear all,
Please can you help me to understand what is required to re-write some code snippets meant for use with the lovely (but pricey) Adafruit i2c connected lcd shield? That shield uses an extended version of the LiquidCrystal library with extra functions including lcd.readButtons(). I want to replace the shield with a standard hitachi style lcd (that I can do) and 5 simple push switches. The switches are connected to pins declared:
// Setup button inputs
const int RightbuttonPin = 18;
const int DownbuttonPin = 19;
const int UpbuttonPin = 20;
const int ShiftbuttonPin = 21;
const int LeftbuttonPin = 22;
// Setup up values for button states
int BUTTON_UP = 0;
int BUTTON_DOWN = 0;
int BUTTON_SHIFT = 0;
int BUTTON_RIGHT = 0;
int BUTTON_LEFT = 0;
And initialised:
void setup()
{
// Setup button inputs and activate internal pull up resistors
pinMode(UpbuttonPin, INPUT_PULLUP);
pinMode(ShiftbuttonPin, INPUT_PULLUP);
pinMode(DownbuttonPin, INPUT_PULLUP);
pinMode(LeftbuttonPin, INPUT_PULLUP);
pinMode(RightbuttonPin, INPUT_PULLUP);
So that I can read the values in the normal way:
BUTTON_UP = digitalRead(UpbuttonPin);
BUTTON_DOWN = digitalRead(DownbuttonPin);
BUTTON_SHIFT = digitalRead(ShiftbuttonPin);
BUTTON_RIGHT = digitalRead(RightbuttonPin);
BUTTON_LEFT = digitalRead(LeftbuttonPin);
Which all works as intended. So here is the question. In the (Arduino Sous-Vide Cooker) What is Sous Vide? | Sous-vide controller powered by Arduino - The SousViduino! | Adafruit Learning System project the main loop waits for the ReadButtons function:
while(ReadButtons() != 0) {}
The original function is like this:
// ************************************************
// Check buttons and time-stamp the last press
// ************************************************
uint8_t ReadButtons()
{
uint8_t buttons = lcd.readButtons();
if (buttons != 0)
{
lastInput = millis();
}
return buttons;
}
And I have tried to emulate that by doing this:
// ************************************************
// Check buttons and time-stamp the last press
// ************************************************
uint8_t ReadButtons()
{
BUTTON_UP = digitalRead(UpbuttonPin);
BUTTON_DOWN = digitalRead(DownbuttonPin);
BUTTON_SHIFT = digitalRead(ShiftbuttonPin);
BUTTON_RIGHT = digitalRead(RightbuttonPin);
BUTTON_LEFT = digitalRead(LeftbuttonPin);
uint8_t buttons;
if (BUTTON_UP || BUTTON_DOWN || BUTTON_SHIFT ||BUTTON_RIGHT || BUTTON_LEFT){buttons = 1;}else{buttons = 0;}
if (buttons != 0)
{
lastInput = millis();
}
return buttons;
}
But it never releases the main loop. Hoping someone can point me in the right direction (sorry for asking what I am sure is a silly question but have been searching and tinkering for hours now) Thank you!