Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup() {
- Serial.begin(9600); //Sets up the serial connection to the serial monitor
- int ONE = 23;
- int TWO = 22;
- int THREE = 21;
- int FOUR = 20;
- pinMode(ONE, OUTPUT); //set pin 23 to OUTPUT
- pinMode(TWO, OUTPUT); //set pin 22 to OUTPUT
- pinMode(THREE, OUTPUT); //set pin 21 to OUTPUT
- pinMode(FOUR, OUTPUT); //set pin 20 to OUTPUT
- int FIVE = 11;
- int SIX = 10;
- int SEVEN = 9;
- int EIGHT = 8;
- pinMode(FIVE, INPUT); //set pin 11 to INPUT (read mode)
- pinMode(SIX, INPUT); //set pin 10 to INPUT (read mode)
- pinMode(SEVEN, INPUT); //set pin 9 to INPUT (read mode)
- pinMode(EIGHT, INPUT); //set pin 8 to INPUT (read mode)
- }
- void loop() {
- digitalWrite(23,HIGH); //Ties pin 23 high for matrix detection
- if (digitalRead(11) == HIGH) {Serial.print("D4 ");} //Prints "D4" to serial monitor
- if (digitalRead(10) == HIGH) {Serial.print("C4 ");} //Prints "C4" to serial monitor
- if (digitalRead(9) == HIGH) {Serial.print("A4 ");} //Prints "A4" to serial monitor (note pin 9 and 8 are wired backwards woops)
- if (digitalRead(8) == HIGH) {Serial.print("B4 ");} //Prints "B4" to serial monitor (note pin 9 and 8 are wired backwards woops)
- digitalWrite(23, LOW);
- Serial.println();
- delay(100);
- digitalWrite(22,HIGH); //Ties pin 23 high for matrix detection
- if (digitalRead(11) == HIGH) {Serial.print("D3 ");} //Prints "D3" to serial monitor
- if (digitalRead(10) == HIGH) {Serial.print("C3 ");} //Prints "C3" to serial monitor
- if (digitalRead(9) == HIGH) {Serial.print("A3 ");} //Prints "A3" to serial monitor (note pin 9 and 8 are wired backwards woops)
- if (digitalRead(8) == HIGH) {Serial.print("B3 ");} //Prints "B3" to serial monitor (note pin 9 and 8 are wired backwards woops)
- digitalWrite(22, LOW);
- Serial.println();
- delay(100);
- digitalWrite(21,HIGH); //Ties pin 23 high for matrix detection
- if (digitalRead(11) == HIGH) {Serial.print("D2 ");} //Prints "D4" to serial monitor
- if (digitalRead(10) == HIGH) {Serial.print("C2 ");} //Prints "C4" to serial monitor
- if (digitalRead(9) == HIGH) {Serial.print("A2 ");} //Prints "A4" to serial monitor (note pin 9 and 8 are wired backwards woops)
- if (digitalRead(8) == HIGH) {Serial.print("B2 ");} //Prints "B4" to serial monitor (note pin 9 and 8 are wired backwards woops)
- digitalWrite(21, LOW);
- Serial.println();
- delay(100);
- digitalWrite(20,HIGH); //Ties pin 23 high for matrix detection
- if (digitalRead(11) == HIGH) {Serial.print("D1 ");} //Prints "D3" to serial monitor
- if (digitalRead(10) == HIGH) {Serial.print("C1 ");} //Prints "C3" to serial monitor
- if (digitalRead(9) == HIGH) {Serial.print("A1 ");} //Prints "A3" to serial monitor (note pin 9 and 8 are wired backwards woops)
- if (digitalRead(8) == HIGH) {Serial.print("B1 ");} //Prints "B3" to serial monitor (note pin 9 and 8 are wired backwards woops)
- digitalWrite(20, LOW);
- Serial.println();
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement