2 //example use of LCD4Bit_mod library
4 #include <LCD4Bit_mod.h>
5 //create object to control an LCD.
6 //number of lines in display=1
7 LCD4Bit_mod lcd = LCD4Bit_mod(2);
10 char msgs[5][15] = {"Right Key OK ",
15 int adc_key_val[5] ={30, 150, 360, 535, 760 };
22 pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
25 //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
26 //lcd.commandWrite(0x0F);//cursor on, display on, blink on. (nasty!)
28 lcd.printIn("KEYPAD testing... pressing");
33 adc_key_in = analogRead(0); // read the value from the sensor
34 digitalWrite(13, HIGH);
35 key = get_key(adc_key_in); // convert into key press
37 if (key != oldkey) // if keypress is detected
39 delay(50); // wait for debounce time
40 adc_key_in = analogRead(0); // read the value from the sensor
41 key = get_key(adc_key_in); // convert into key press
46 lcd.cursorTo(2, 0); //line=2, x=0
47 lcd.printIn(msgs[key]);
53 digitalWrite(13, LOW);
61 // Convert ADC value to key number
62 int get_key(unsigned int input)
66 for (k = 0; k < NUM_KEYS; k++)
68 if (input < adc_key_val[k])
76 k = -1; // No valid key pressed