Here is some code I wrote quick to get the reading of the 'A0' pin on my Sainsmart LCD Keypad Shield.
I'm hoping this code helps others how the keypad works, and perhaps will help integrate the keypad into some more understandable / newbie-friendly coding and projects.
Here's the code!
//
//Program: Sainsmart_LCD_Button_Readings
//
//Author: Jester_Baze
//
//Requires: -Sainsmart LCD Keypad Shield
// -Arduino Uno R3
//
/*
This program shows the value of the reading
taken from pin A0 then displays it on the
LCD shield. Hopefully this code is easier
to digest than some of the google results.
This is designed to make the Sainsmart LCD
Keypad Shield more newbie friendly.
Hope this helps!
*/
#include <SPI.h>
#include <LiquidCrystal.h>
//Define your lcd pins
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );
//Some notes I took...
//Mapped & Analog readouts from "A0" -- Keypad input
/*
Nothing pressed = 100 or 1023
'Select' - 72 or 743
'Left' - 49 or 507
'Right' - 0 or 0
'Up' - 14 or 145/146
'Down' - 32 or 331
*/
void setup()
{
lcd.begin(16,2); //'16,2' is 16 columns, 2 rows on the display
Serial.begin(9600);
pinMode(A0, INPUT); //pin 'A0' is your keypad's input.
}
void loop()
{
//Read the A0 keypad pin
int keypadInput = analogRead(A0);
//Map it to a number between 0-100
int keypadRead = map(keypadInput, 0, 1023, 0, 100);
//Display the readings on the keypad
Serial.println(keypadInput);
lcd.print("Mapped: ");
lcd.print(keypadRead);
//Move the cursor down to line two
lcd.setCursor(0,1);
lcd.print("Actual: ");
lcd.print(keypadInput);
lcd.setCursor(0,0);
//To help things work nice and pretty-like =)
delay(150);
lcd.clear();
}