// Let's see some values forour resistor based keypad! int keypad; // We'll place our result here int decoded; // We'll place the decoded result here void setup() { Serial.begin(9600); // Ready the serial monitor, so that we can see the result } void decode() // This function takes our Analog to Digital reading, and decodes it. { if (keypad < 150) // For example, is the analog to digital (AD) value smaller than 150? If yes, return with a value of 10 (Button#10 pressed) { decoded = 10; } else if (keypad < 250) // Otherwise, is the AD value stored in keypad smaller than 250? If so, return with a value of 9 (Button#9 pressed). { decoded = 9; } else if (keypad < 320) // Otherwise, yadda yadda yadda =D { decoded = 8; } else if (keypad < 400) { decoded = 7; } else if (keypad < 480) { decoded = 6; } else if (keypad < 560) { decoded = 5; } else if (keypad < 660) { decoded = 4; } else if (keypad < 770) { decoded = 3; } else if (keypad < 860) { decoded = 2; } else if (keypad < 960) { decoded = 1; } } void loop() // Let's git-er done! { keypad = analogRead(0); // Take an Analog reading on A0, and place the result into INT RESULT if (keypad > 40) { delay(150); // Wait 100ms for debounce/settle decode(); // Call the decode function Serial.print("You Pressed Button#"); // Print on the serial communicator "You Pressed Button#" Serial.println(decoded); // Print the decoded button that you pressed on the screen while (analogRead(0) > 40) { // Do nothing while ANY button is being pressed. {} } delay(150); // After you've let go of the button, the A0 pin should read 0, so delay to account for bounce, and loop again. } }