I have seen multiple threads about how to put your pins to HIGH or LOW and then if they change then do this. Or if they stay the same do this. I have recently put together a code that does not use that. I use a button state within the lcd.readbuttons. Should I do this another way?
I want to scroll the screen with the up and down arrows and then select the item I want. I am so close yet I cannot seem to understand what I am missing. I put in the code. Is there anyone who can point me in the right direction? I would love to understand this.
// include the library code:
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
#include "PartNumberToAddressToPSI_Type.h"
#include <avr/pgmspace.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
#define adr 0x28 // Address of part
char const* ADDR;
char const* MPN;
char const* MPN2;
char const* MPN3;
char const* VSS[]={"SS5AI100GP","PSI A", "PSI G"};
uint8_t i=0;
int j = 0;
int Partcounter;
char myChar;
int PushButtonCounter;
//Declare my Variables
void setup() {
// Debugging output
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
//int time = millis();
lcd.setCursor(3,0);
lcd.print("Select the");
lcd.setCursor(5,1);
lcd.print("Sensor");
//time = millis() - time;
//Serial.print("Took "); Serial.print(time); Serial.println(" ms");
lcd.setBacklight(WHITE);
for (int i = 0; i < 3 ;i++){
MPN = VSS[i-2];
MPN2 = VSS[i-1];
MPN3 = VSS[i];}
}
void loop() {
uint8_t buttons = lcd.readButtons();
if (buttons) {
lcd.clear();
lcd.setCursor(0,0);
if (buttons & BUTTON_UP)
{
lcd.setCursor(3,0);
lcd.print(MPN);
lcd.setBacklight(RED);
lcd.setCursor(5,1);
lcd.print("0x28H");
delay(50);
j = 1;
if (buttons & BUTTON_UP);
{
j++;
}
}
if (buttons & BUTTON_DOWN) {
lcd.print(MPN);
lcd.setBacklight(YELLOW);
j = 2;
}
if (buttons & BUTTON_LEFT) {
lcd.print("LEFT ");
lcd.setBacklight(GREEN);
j = 3;
}
if (buttons & BUTTON_RIGHT) {
lcd.print("RIGHT ");
lcd.setBacklight(TEAL);
j = 4;
}
if (buttons & BUTTON_SELECT) {
if (j == 2)
{
lcd.print("You pushed down");
lcd.setBacklight(VIOLET);
for (Partcounter = 7; Partcounter < 14; Partcounter++)
{
myChar = pgm_read_byte_near(Part + Partcounter);
lcd.setCursor(Partcounter - 8,1);
lcd.print(myChar);
}
delay(50);
for (Partcounter = 0; Partcounter < 5; Partcounter++)
{
myChar = pgm_read_byte_near(PSI + Partcounter);
lcd.setCursor(Partcounter + 8,1);
lcd.print(myChar);
}
delay(50);
}
else if ( j == 1) {
lcd.print("You pushed up");
lcd.setBacklight(GREEN);
for (Partcounter = 0; Partcounter < 6; Partcounter++)
{
myChar = pgm_read_byte_near(Part + Partcounter);
lcd.setCursor(Partcounter,1);
lcd.print(myChar);
}
delay(50);
for (Partcounter = 6; Partcounter < 12; Partcounter++)
{
myChar = pgm_read_byte_near(PSI + Partcounter);
lcd.setCursor(Partcounter + 2,1);
lcd.print(myChar);
}
delay(50);
}
else if (j == 3){
lcd.print("You pushed Left");
lcd.setBacklight(BLUE);
}
else if (j == 4){
lcd.print("You pushed Right");
lcd.setBacklight(WHITE);
}
else{
lcd.setBacklight(RED);
lcd.print("False");
}
}
}
}