【发布时间】:2021-08-21 08:25:11
【问题描述】:
我正在开发一个计算器,就像在计算器中按多少按钮一样工作。例如,我按了四次按钮,现在计算器中的数字是四。但问题是,当 Arduino 开启时,数字会在没有触摸按钮的情况下上升。我能做些什么?我正在使用数字显示器、Arduino UNO 板和四个按钮,这是我的代码:
#include <TM1637.h>
// this is a calculater with four buttons on pins 2 3 4 5 and a number display and the driver is TM1637 CLK on pin 13 and DIO on pin 12. after making sure you connected
// all the modules you can program these codes on your Arduino UNO. LET'S JUTS MAKE IT!
const int btn_one = 2;
const int btn_two = 3;
const int btn_three = 4;
const int btn_four = 5;
/*
int b1s = LOW;
int b2s = LOW;
int b3s = LOW;
int b4s = LOW;
*/
int num1 = 0;
int num2 = 0;
int mathop = 1;
int CLK = 13;
int DIO = 12;
TM1637 tm(CLK,DIO);
void setup(){
tm.init();
tm.set(7);
pinMode(btn_one, INPUT);
pinMode(btn_two, INPUT);
pinMode(btn_three, INPUT);
pinMode(btn_four, INPUT);
}
void loop(){
int b1s = digitalRead(btn_one);
int b2s = digitalRead(btn_two);
int b3s = digitalRead(btn_three);
int b4s = digitalRead(btn_four);
if(b1s == true){
num1 = num1 + 1;
displayNumber(num1);
//digitalWrite(btn_one, LOW);
delay(1000);
}
}
void displayNumber(int num){
tm.display(3, num % 10);
tm.display(2, num / 10 % 10);
tm.display(1, num / 100 % 10);
tm.display(0, num / 1000 % 10);
}
这些是我的联系: Connections 1 Connections 2
如果你能帮助我,请给我一个对我很有帮助的答案,非常感谢。
【问题讨论】:
-
你的输入引脚是浮动的
-
我能做什么?我是 arduino 的新手
-
跟随一个基本的按钮教程。
标签: arduino calculator