//
//Reading 4x4 Keypad with ONE Arduino Pin
// credit to Hari Wiguna, 2016
#include "ssd1306.h"
//KEYPAD-----
int threshold[16] = {204, 146, 78, 0, 371, 334, 293, 248, 481, 456, 429, 399, 559, 541, 522, 500};
char keypad[16] = {'1', '2', '3', 'T', '4', '5', '6', 'L', '7', '8', '9', 'R', '.', '0', '#', 'C'};
//OLED-----
//SETUP-----
void setup(){
Serial.begin(9600);
}
void loop(){
int value = analogRead(A0);
for (int i = 0; i < 16; i++)
{
//Is A0 close enough to one of the keypad values?
if(abs(value - threshold[i]) < 5)
{
//Yes, translate the index of that value to the actual name of the key
Serial.println(keypad[i]);
//Wait until they release the button
while (analogRead(A0) < 1000) {delay(100);}
}
}
}Loading
cd74hc4067
cd74hc4067