借鸡生蛋你没看到

#include <LiquidCrystal.h>
#include <Time.h>

// 定义 LCD1602 引脚
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// 定义矩阵键盘引脚
const int rowPins[4] = {9, 8, 7, 6};
const int colPins[4] = {A0, A1, A2, A3};

// 定义开机动画标志
bool isAnimation = true;

// 定义当前输入值和操作符
float num1 = 0, num2 = 0, op = 0;

// 定义时间相关变量
time_t now;
struct tm *timeinfo;

void setup() {
  // 初始化 LCD1602
  lcd.begin(16, 2);

  // 初始化矩阵键盘
  for (int i = 0; i < 4; i++) {
    pinMode(rowPins[i], INPUT_PULLUP);
  }
  for (int i = 0; i < 4; i++) {
    pinMode(colPins[i], OUTPUT);
  }

  // 获取当前时间
  now = time(NULL);
  timeinfo = localtime(&now);

  // 显示初始信息
  showDateTime();
}

void loop() {
  // 处理矩阵键盘输入
  handleKeypadInput();

  // 处理开机动画和计算功能切换
  if (isAnimation) {
    // 开机动画逻辑
    //...
  }
}

// 处理矩阵键盘输入函数
void handleKeypadInput() {
  // 遍历矩阵键盘
  for (int row = 0; row < 4; row++) {
    digitalWrite(colPins[row], LOW);
    for (int col = 0; col < 4; col++) {
      if (!digitalRead(rowPins[col])) {
        // 处理按键输入逻辑
        //...
      }
    }
    digitalWrite(colPins[row], HIGH);
  }
}

// 显示日期时间函数
void showDateTime() {
  lcd.setCursor(0, 0);
  lcd.print(year + 1900);
  lcd.print('-');
  lcd.print(month + 1);
  lcd.print('-');
  lcd.print(day);

  lcd.setCursor(0, 1);
  if (hour < 12) {
    lcd.print("AM ");
  } else {
    lcd.print("PM ");
  }
  lcd.print(hour);
  lcd.print(':');
  lcd.print(minute);
  lcd.print(':');
  lcd.print(second);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值