Hello, I recently purchased an LCD1602 which contains on it 5 buttons. The buttons are all connected to analog AO and each one outputs a different voltage. My goal is to have a user use the LCD1602 to scroll through a list of songs and select which song they'd like to play. I'd like the top row to say "please select song," and have the bottom row be where the song titles appear. The part that I'm having the most difficult time with is interpreting the analog input and then using that input to call a function which either scrolls right or left in an array containing all of the song titles. I haven't even tried to figure out how I'm going to actually select the song to be played, but I'm sure that will be a challenge in itself.
Here's what I have thus far. Any suggestions are greatly appreciated.
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
char* songList[4] = {"Ain't Misbehavin", "Dry Bones", "Toccata and Fugue" , '\0'};
char* currentSong = songList[0];
char* lastSong;
int adc_key_in = 0;
int i = 0;
void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Fats Industries");
delay(1000);
lcd.clear();
lcd.print("Select Song");
}
void loop()
{
lcd.setCursor(0, 1);
switch (read_LCD_buttons())
{
case btnUP:
{
i++;
currentSong = songList[i];
lcd.print(" ");
lcd.print(currentSong);
break;
}
case btnDOWN:
{
i--;
currentSong = songList[i];
lcd.print(" ");
lcd.print(currentSong);
break;
}
case btnNONE:
{
lcd.print(currentSong);
break;
}
}
}
int read_LCD_buttons()
{
adc_key_in = analogRead(0);
if (adc_key_in > 1000) return btnNONE;
//if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
//if (adc_key_in < 555) return btnLEFT;
//if (adc_key_in < 790) return btnSELECT;
return btnNONE;
}