c++ - 如何根据光电管值更改的次数将显示的值增加到七段显示?
问题描述
所以我一直在研究一个应该模拟激光绊线的 arduino 项目。激光照射到光敏电阻上,每次输入板的电压由于没有光而增加,板应该将counter
变量显示到七段显示器。
但无论出于何种原因,只要电阻器被激活,它就会counter = counter + 1
无限次地执行该行。我只希望计数器在每次激活时增加一次,而不是在光敏电阻增加电压时激活。
这里有人可以帮忙吗?
#include "SevSeg.h"
SevSeg sevseg;
const int pResistor = A0;
//the photoresistor is connected to analog input pin A0
int count; //number of times voltage is increased
int value; //voltage reading of A0
void setup() {
pinMode(pResistor, INPUT);
byte numDigits = 1;
byte digitPins[]={};
byte segmentPins[]={6, 5, 2, 3, 4, 7, 8, 9};
bool resistorsOnSegments = true;
byte hardwareConfig = COMMON_CATHODE;
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
sevseg.setBrightness(90);
}
void loop() {
value=analogRead(pResistor);
//here's where my problem starts
while (count < 9){
if (value>1022){
//it should be noted that the photoresistor is preceded by a 100k Ω resistor, which
//explains the large value
sevseg.setNumber(count);
}
else{
count = count + 1;
sevseg.setNumber(count);
}
}
//here's where my problem ends
sevseg.refreshDisplay();
}
解决方案
推荐阅读
- javascript - 使用 setter 设置属性添加属性而不是设置它
- docker - 无法从 Apache Beam 中的本地模拟器读取 Pub/Sub 消息
- vba - VBA - 如何找到从效果创建的形状的名称?
- c# - 如何在 Xamarin.Forms 中直播 .m3u8 视频文件
- javascript - 为重命名的解构变量分配默认值
- vue.js - 渲染后过滤 2 个不同的组件
- c++ - 向量元素类型的特征稀疏矩阵的 CoeffRef 误差
- apache-spark - 使用 Apache Beam 而不是直接使用 Spark 的缺点/问题?
- jquery - 防止 css 过渡在多个 mouseenter 上重叠
- sql - 如何在 SQL 中合并三个大文本文件以准备导出到 SPSS 和 R