Newb需要知道如何构建一个简单的计数器 [英] Newb needs to know how to build a simple counter
问题描述
我有一个有问题的程序。
它假设从控制器读取输入,然后当控制器打开时,它会在每5分钟循环检查中执行X. />
问题是我时不时地从控制器那里得到错误的读数。
所以我想做的是添加一个小计数器以便它检查4次
并且只有当它连续变成4时它才会执行x。
类似for(int i = 0; i< 4; i ++)
进入此
I have a program that''s having problems.
Its suppose to read the input from a controller then when the controller is on, it does X in a loop checking every 5mins.
Problem is I get faulty readings from the controller every now and then.
So what I want to do, is add a little counter so it checks it 4 times
and only when it gets 4 in a row it does x.
something like for (int i = 0; i < 4; i++)
into this
public static void Method_6()
{
Thread.Sleep(2 * HourMs);
while((method_state_6) && (!phcontroller.Read())) //phcontroller is just a relay that closes when needed
{
ph.Write(false);
Thread.Sleep(2000);
ph.Write(true);
Thread.Sleep(5 * MinuteMs);
}
}
我是新手,有点迷失怎么办
I''m a new and a little lost how to do it
推荐答案
您可以尝试以下方法:
You can try something like:
int i = 0;
bool flag = true;
while (i < 4 && flag)
{
flag = inputSource;
}
if (flag)
do X
如果标志连续4次为真,它将执行X.
If flag is true 4 times in a row, it will perform X.
这篇关于Newb需要知道如何构建一个简单的计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!