Key_Lcd1602_I2C — Arduino Uno simulation

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by tcflm.

Components

Sketch code

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;
#define LED 13 
//键盘布局
const char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

//行R1‑R4接D2,D3,D4,D5
byte rowPins[ROWS] = {2, 3, 4, 5};
//列C1‑C4接D8,D9,D10,D11
byte colPins[COLS] = {8, 9, 10, 11};

//⚠️构造函数顺序:makeKeymap(keys),行数组,列数组,行数,列数
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
  Serial.begin(9600);
 pinMode(LED, OUTPUT);
}

void loop() {
  char key = keypad.getKey();
  if(key != NO_KEY)
  {
    digitalWrite(LED , HIGH);
    Serial.println(key);
  }
  delay(150);
 digitalWrite(LED, LOW);
}

More projects by tcflm