raspberry-pi - 数一数二开关量输入
问题描述
#define GRN_LED 23
#define RED_LED 25
#define YEL_LED 12
#define RED_SW 22
#define GRN_SW 17
#define YEL_SW 6
int red_sw;
int grn_sw;
int yel_sw;
int red_cnt=0;
int grn_cnt=0;
int yel_cnt=0;
int tot = 0;
int main(void)
{
wiringPiSetupGpio();
pinMode(RED_SW, INPUT);
pinMode(GRN_SW, INPUT);
pinMode(YEL_SW, INPUT);
while(1)
{
if(digitalRead(RED_SW)==LOW)
{
red_cnt++;
printf("Click: R(%d) G(%d) Y(%d)\n", red_cnt, grn_cnt, yel_cnt);
}
if(digitalRead(GRN_SW)==HIGH)
{
grn_cnt++;
printf("Click: R(%d) G(%d) Y(%d)\n", red_cnt, grn_cnt, yel_cnt);
}
if(digitalRead(YEL_SW)==LOW)
{
yel_cnt++;
printf("Click: R(%d) G(%d) Y(%d)\n", red_cnt, grn_cnt, yel_cnt);
}
}
return 0;
}
![文本]( https://stackoverflow.com/image [![在此处输入图像描述] 1 ] 1 .jpg)
我正在使用树莓派。我正在尝试计算切换次数。如果我按下红色开关,红色开关只数一个。但就像上图一样,当我按下开关时,它会继续计算数字。我怎样才能只数一次按一次?
解决方案
推荐阅读
- java - 单击时Java-FX接收Shape-Array的索引
- java - 线程之间的Java共享变量
- javascript - 允许在内容可编辑的末尾移出跨度
- angular - 当你的函数接受一个包含 | 的参数时,这意味着什么?象征?
- scala - 弃用类构造函数参数
- javascript - 在 Symfony 3 中使用 ajax 提交多个表单?
- parallel-processing - 在 Rust 中,是否可以在没有静态生命周期的情况下在多个线程之间共享数据?
- java - ServiceLoader 中的 Iterable 对象是否已排序?
- php - 销毁 PHP $_SESSION 数组元素
- windows - 多个客户端 - 一台服务器 - 一个端口?