Hey everyone
It's me, again
So, here's the code
/*-----( Import needed libraries )-----*/
#include <LiquidCrystal.h>
/*-----( Declare objects )-----*/
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //These are the pins used on this shield
/*-----( Declare Constants )-----*/
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
/*-----( Declare Variables )-----*/
int lcd_key = 0;
int adc_key_in = 0;
int adc_key_prev = 0;
byte numbChar = '0';
int lettChar = 'a';
void setup() /*----( SETUP: RUNS ONCE )----*/
{
lcd.begin(16, 2); // start the lcd object
}/*--(end setup )---*/
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
lcd.setCursor(9, 0); //set cursor to (9, 0)
lcd.write(lettChar); //print "a"
lcd.setCursor(9, 1); //set cursor to (9, 1);
lcd.write(numbChar); //print "0"
adc_key_prev = lcd_key ; // Looking for changes
lcd_key = read_LCD_buttons(); // read the buttons
lcd.setCursor(0,1); // move to the begining of the second line
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
lcd.setCursor(10, 1);
lcd.print(" ");
numbChar++;
lcd.setCursor(9, 1);
lcd.write(numbChar);
delay(250);
if (numbChar == '9')
{
delay(250);
numbChar = '0';
}
break;
}
case btnLEFT:
{
lcd.setCursor(10, 1);
lcd.print(" ");
numbChar--;
lcd.setCursor(9, 1);
lcd.write(numbChar);
delay(250);
if (numbChar == '0')
{
delay(250);
numbChar = '9';
}
break;
}
case btnUP:
{
lcd.setCursor(10, 0);
lcd.print(" ");
lettChar++;
lcd.setCursor(9, 0);
lcd.write(lettChar);
if (lettChar == 'z')
delay(250);
{
delay(250);
lettChar = 'a';
}
break;
}
case btnDOWN:
{
lcd.setCursor(10, 0);
lcd.print(" ");
lettChar--;
lcd.setCursor(9, 0);
lcd.write(lettChar);
if (lettChar == 'a')
delay(250);
{
delay(250);
lettChar = 'z';
}
break;
}
case btnSELECT:
{
lcd.print("SELECT");
break;
}
case btnNONE:
{
lcd.print("NONE ");
break;
}
}/* --(end switch )-- */
}/* --(end main loop )-- */
/*-----( Declare User-written Functions )-----*/
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
delay(5); //switch debounce delay. Increase this delay if incorrect switch selections are returned.
int k = (analogRead(0) - adc_key_in); //gives the button a slight range to allow for a little contact resistance noise
if (5 < abs(k)) return btnNONE; // double checks the keypress. If the two readings are not equal +/-k value after debounce delay, it tries again.
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
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; // when all others fail, return this...
}
How to make that when numbChar reaches 9, lcd will write 0, and rerversed...
How to make that when lettChar reaches z, lcd will print a, and reversed...
Thanks for help