c++ - 使用 Arduino 在串行监视器上显示错误值的键盘
问题描述
当我从键盘按 A 时,它会调用函数 shahbaz ,然后我从键盘输入一些值,该值与 int a 相乘并在七段显示结果。但在七段显示上没有显示结果。当我在串行上打印此结果时。监视器。它显示错误的答案,如(-960,000) 。当我尝试将值与键盘值相乘时,七段显示显示0000它显示错误的答案。如果我输入 t=1200*20 ;没有从键盘输入值它在串行监视器和七段显示器上显示正确的答案
#include <Keypad.h>
#include "LedControl.h"
LedControl lc = LedControl(11,3,4,1); //DIN, SCK, LOAD,1xMAX7219
int a=20;
int b=30;
int c=37;
int d=40;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = { A0, A1, A2, A3};
byte colPins[COLS] = { A4, 5, 6, 7};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// inputString.reserve(10);
lc.shutdown(0,false); // Wake up the display
lc.setIntensity(0,7);
//lc2.setIntensity(0,7);// Set Brightness 0-15
lc.clearDisplay(0); // Clear display
}
void loop() {
// put your main code here, to run repeatedly:
char customKey = customKeypad.getKey();
customKey=customKey-'0';
if(customKey=='A'){// when press it go to function shahbaz.
shahbaz();
}
}
void shahbaz(){
char customKey = customKeypad.getKey();
customKey=customKey-'0';
long int t=a*customKey;
Serial.print(t);
Serial.print(customKey);
long int t=customKey*a; // here get value from keypad and multiply with value of //int a but it show nothing when i print this value on serial monitor it show -960
int digitOne = (t%10);
int digitTwo = (t/10)%10;
int digitThree = (t/100)%10;
int digitFour = (t/1000)%10;
int digitFive = (t/10000)%10;
int digitSix = (t/100000)%10;
int digitSeven= (t/1000000)%10;
int digitEight = (t/10000000)%10;
//MSB digitEight, LSB digitOne
lc.setDigit(0,7,digitEight,false);
lc.setDigit(0,6,digitSeven,false);
lc.setDigit(0,5,digitSix,false);
lc.setDigit(0,4,digitFive,false);
lc.setDigit(0,3,digitFour,false);
lc.setDigit(0,2,digitThree,false);
lc.setDigit(0,1,digitTwo,false);
lc.setDigit(0,0,digitOne,false);
delay(1000);
}
解决方案
推荐阅读
- unity3d - 像 Gameobject 一样缩放 UI
- android - 无法在设置了 compileOptions 的情况下运行“gradlew”
- dotnetnuke - 如何制作和使用不同的页面布局?
- adsense - TagError:adsbygoogle.push() 错误:当我使用响应式广告时,availableWidth=0 没有插槽大小
- javascript - 如何有效地检查鼠标是否在 HTML5 画布中的许多(120)个不同区域中?
- python - 使用 Python 导入日期和时间列数据
- javascript - 无法将数组缓冲区转换为字符串?
- r - 提取分割数据的cor检验的p值
- arrays - 对具有相同范围的多个工作表进行排序
- mysql - 删除重复的 UNION ALL 检索到的帖子 sql、mysql