为什么Arduino IDE中的相同代码会在不同的笔记本电脑上提供不同的输出?

时间:2017-08-08 18:10:56

标签: arduino embedded system i2c keypad

我试图通过I2C(PCF8574AT)转换器模块与Arduino Uno连接键盘(4 * 4膜型)。

A1,A2,A3引脚接地。所以I2CADDR是0x38。

在我的Lenovo T440上编译并运行此代码,它显示:

Press anykey:
B

然后无论我按下键盘多少次,串行显示器上都不会出现任何问题。另一方面,当我在T430s上运行相同的代码时,它运行成功。

显示

Press any key:
and then on pressing key it was showing 1,2 ,3 etc

Arduino版本在两者上都使用了1.8.2。 完全相同的代码和库仍然不同的输出。 任何人都可以解释原因吗?

这是我的代码:

/* @file CustomKeypad.pde
  || @version 1.0
  || @author Alexander Brevig
  || @contact alexanderbrevig@gmail.com
  ||
  || @description
  || | Demonstrates changing the keypad size and key values.
  || #
    Use with I2C i/o G. D. (Joe) Young Feb 28/12
*/

#include <Keypad_I2C.h>
#include <Keypad.h> // GDY120705
#include <Wire.h>

#define I2CADDR 0x38
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the symbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6, 7}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad_I2C customKeypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS, I2CADDR);

void setup() {
  // Wire.begin();
  customKeypad.begin(); // GDY120705
  Serial.begin(9600);
  Serial.println("Press Keys");
}

void loop() {
  char customKey = customKeypad.getKey();
  if (customKey != NO_KEY) {
    Serial.println(customKey);
  }
}

1 个答案:

答案 0 :(得分:0)

首先验证您的硬件。 我很久以前在开发一个8 * 8键矩阵的项目时尝试过这个问题。它可能是某个地方港口变化太快而没有放电因此造成误触发。