printf("ho_tari\n");

16_Keypad_4x4 본문

Arduino

16_Keypad_4x4

호타리 2023. 9. 2. 12:39
const int ROW[4] = {13, 12, 11, 10};  //OUTPUT
const int COL[4] = {9, 8, 7, 6};   //INPUT
int colVal[4] = {LOW};

void setup() {
  // put your setup code here, to run once:
  for (int i = 0; i < 4; i++) {
    pinMode(ROW[i], OUTPUT);
    digitalWrite(ROW[i], LOW);

    pinMode(COL[i], INPUT); 
  }

  Serial.begin(115200);

}

void loop() {
  // put your main code here, to run repeatedly:
  for(int i = 0; i < 4; i++) {
    digitalWrite(ROW[i], HIGH);
    //col read
    for(int j = 0; j < 4; j++) {
      colVal[j] = digitalRead(COL[j]);
    }

    digitalWrite(ROW[i], LOW);

    for(int j = 0; j < 4; j++) {
      if(colVal[j] == HIGH) {
        // Serial.print("Row: ");
        // Serial.print(i);
        // Serial.print(" , Col: ");
        // Serial.print(j);
        // Serial.print(" -> ");
        Serial.println(i * 4 + j, HEX);

        delay(200);
      }
    }
  }

}

'Arduino' 카테고리의 다른 글

EX01_Binary_LED  (0) 2023.09.02
17_Multi_Task  (0) 2023.09.02
15_ArrayFND  (0) 2023.09.02
14_FND  (0) 2023.09.02
13_PCINT_Ultrasonic  (0) 2023.09.02