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");
31 Serial.println("Keypad testing over serial");
36 adc_key_in = analogRead(0); // read the value from the sensor
37 digitalWrite(13, HIGH);
38 key = get_key(adc_key_in); // convert into key press
40 if (key != oldkey) // if keypress is detected
42 delay(50); // wait for debounce time
43 adc_key_in = analogRead(0); // read the value from the sensor
44 key = get_key(adc_key_in); // convert into key press
49 lcd.cursorTo(2, 0); //line=2, x=0
50 lcd.printIn(msgs[key]);
52 Serial.print(adc_key_in);
53 Serial.print(" key=");
60 digitalWrite(13, LOW);
68 // Convert ADC value to key number
69 int get_key(unsigned int input)
73 for (k = 0; k < NUM_KEYS; k++)
75 if (input < adc_key_val[k])
83 k = -1; // No valid key pressed