Created
February 24, 2025 00:03
-
-
Save lopespm/0716fbecc080b6ba06d4240e269124f5 to your computer and use it in GitHub Desktop.
Using a arduino keypad module from scratch, without using extra libraries. In this case, two columns are targeted. This gist is a complement to https://youtu.be/1iPnFEWHnqo, where this is explained
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using a a arduino keypad module from scratch, without using extra libraries. | |
// In this case, two columns are targeted | |
// This gist is a complement to https://youtu.be/1iPnFEWHnqo, where this is explained | |
int pinSource1 = 3; | |
int pinSource2 = 4; | |
int pinReceiver1 = 9; | |
int pinReceiver2 = 8; | |
int pinReceiver3 = 7; | |
int pinReceiver4 = 6; | |
bool isPress1Detected = false; | |
bool isPress2Detected = false; | |
void setup() { | |
pinMode(pinSource1, OUTPUT); | |
pinMode(pinSource2, OUTPUT); | |
pinMode(pinReceiver1, INPUT_PULLUP); | |
pinMode(pinReceiver2, INPUT_PULLUP); | |
pinMode(pinReceiver3, INPUT_PULLUP); | |
pinMode(pinReceiver4, INPUT_PULLUP); | |
Serial.begin(9600); | |
} | |
void loop() { | |
if (isPress2Detected == false) { | |
digitalWrite(pinSource1, LOW); | |
if (isPress1Detected == true && (digitalRead(pinReceiver1) == LOW || digitalRead(pinReceiver2) == LOW || digitalRead(pinReceiver3) == LOW || digitalRead(pinReceiver4) == LOW)) { | |
return; | |
} else { | |
isPress1Detected = false; | |
} | |
if (digitalRead(pinReceiver1) == LOW) { | |
isPress1Detected = true; | |
Serial.println("3 was pressed"); | |
} else if (digitalRead(pinReceiver2) == LOW) { | |
isPress1Detected = true; | |
Serial.println("6 was pressed"); | |
} else if (digitalRead(pinReceiver3) == LOW) { | |
isPress1Detected = true; | |
Serial.println("9 was pressed"); | |
} else if (digitalRead(pinReceiver4) == LOW) { | |
isPress1Detected = true; | |
Serial.println("# was pressed"); | |
} | |
digitalWrite(pinSource1, HIGH); | |
} | |
if (isPress1Detected == false) { | |
digitalWrite(pinSource2, LOW); | |
if (isPress2Detected == true && (digitalRead(pinReceiver1) == LOW || digitalRead(pinReceiver2) == LOW || digitalRead(pinReceiver3) == LOW || digitalRead(pinReceiver4) == LOW)) { | |
return; | |
} else { | |
isPress2Detected = false; | |
} | |
if (digitalRead(pinReceiver1) == LOW) { | |
isPress2Detected = true; | |
Serial.println("2 was pressed"); | |
} else if (digitalRead(pinReceiver2) == LOW) { | |
isPress2Detected = true; | |
Serial.println("5 was pressed"); | |
} else if (digitalRead(pinReceiver3) == LOW) { | |
isPress2Detected = true; | |
Serial.println("8 was pressed"); | |
} else if (digitalRead(pinReceiver4) == LOW) { | |
isPress2Detected = true; | |
Serial.println("0 was pressed"); | |
} | |
digitalWrite(pinSource2, HIGH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment