Skip to content

Instantly share code, notes, and snippets.

@lopespm
Last active February 24, 2025 00:30
Show Gist options
  • Save lopespm/2d2ce2701ae8e726a5d497c36283d008 to your computer and use it in GitHub Desktop.
Save lopespm/2d2ce2701ae8e726a5d497c36283d008 to your computer and use it in GitHub Desktop.
Using a arduino keypad module from scratch, without using extra libraries. In this case, one columns is targeted. This gist is a complement to https://youtu.be/1iPnFEWHnqo, where this is explained
// Using a a arduino keypad module from scratch, without using extra libraries.
// In this case, one columns is targeted.
// This gist is a complement to https://youtu.be/1iPnFEWHnqo, where this is explained
int pinSource = 3;
int pinReceiver1 = 9;
int pinReceiver2 = 8;
int pinReceiver3 = 7;
int pinReceiver4 = 6;
bool isPressDetected = false;
void setup() {
pinMode(pinSource, OUTPUT);
pinMode(pinReceiver1, INPUT_PULLUP);
pinMode(pinReceiver2, INPUT_PULLUP);
pinMode(pinReceiver3, INPUT_PULLUP);
pinMode(pinReceiver4, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
digitalWrite(pinSource, LOW);
if (isPressDetected == true && (digitalRead(pinReceiver1) == LOW || digitalRead(pinReceiver2) == LOW || digitalRead(pinReceiver3) == LOW || digitalRead(pinReceiver4) == LOW)) {
return;
} else {
isPressDetected = false;
}
if (digitalRead(pinReceiver1) == LOW) {
isPressDetected = true;
Serial.println("3 was pressed");
} else if (digitalRead(pinReceiver2) == LOW) {
isPressDetected = true;
Serial.println("6 was pressed");
} else if (digitalRead(pinReceiver3) == LOW) {
isPressDetected = true;
Serial.println("9 was pressed");
} else if (digitalRead(pinReceiver4) == LOW) {
isPressDetected = true;
Serial.println("# was pressed");
}
digitalWrite(pinSource, HIGH);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment