|
我打算写一个从4*3的矩阵键盘读取数字并在串口中显示的程序,然后烧进Wifiduino之后串口就一直显示下面的信息,似乎因为看门狗一直在重启。我百度了说在循环里加上喂狗的语句或者加delay就可以了,但是都试过了还是不行,在每个for循环里都加过delay还有ESP.wdt_feed(),还有人说是因为供电不足导致的,求大佬指点[pre]const int numRows = 4;//键盘的行数
const int numCols = 3;//键盘的列数
const int debounceTime = 20;//开关稳定需要的毫秒数
//keymap定义相应的键被按下时返回的字符
const char keymap[numRows][numCols] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
const int rowPins[numRows] = {8, 3, 4, 6};
const int colPins[numCols] = {7, 9, 5};
void setup(){
Serial.begin(9600);
for(int row = 0; row < numRows; row++)
{
pinMode(rowPins[row], INPUT);
digitalWrite(rowPins[row], HIGH);
delay(2000);
}
for(int column = 0; column < numCols; column++)
{
pinMode(colPins[column], OUTPUT);
digitalWrite(colPins[column], HIGH);
}
}
void loop(){
char key = getKey();
if(key != 0)
{
Serial.print("Got key");
Serial.println(key);
}
delay(2000);
}
char getKey()
{
char key = 0;
for(int column = 0; column < numCols; column++)
{
digitalWrite(colPins[column], LOW);
for(int row = 0; row < numRows; row++)
{
delay(100);
if(digitalRead(rowPins[row]) == LOW)
{
delay(debounceTime);
while(digitalRead(rowPins[row]) == LOW);
key = keymap[row][column];
delay(100);
}
delay(100);
}
digitalWrite(colPins[column], HIGH);
}
return key;
}[/pre] |
-
|