我的 Arduino 在等待 1 分钟后停止 [英] My Arduino stops after 1 minute wait

查看:16
本文介绍了我的 Arduino 在等待 1 分钟后停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实有一个小的 Arduino 编程,它在第一次循环后就停止了.我可能会忽略一些东西......但我对正在发生的事情一无所知.

I do have a small Arduino programming that simply stops after first loop. I might overlook something...but I'm simply clueless about what is happening.

这是代码

int led = 13;
//int led = 10;
unsigned long windtime = 1000 * 2; // 2 seconds
unsigned long pausetime = 1000 * 60; // 1 minute

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);

  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  Serial.print("Wind");
  digitalWrite(led, HIGH);
  delay(windtime);               

  Serial.print("Pause");
  digitalWrite(led, LOW);    
  delay(pausetime);
}

我仅将串行用作调试回显.

I used Serial only as debug echo.

有什么想法吗?

推荐答案

看来您需要将数字文字显式设置为 long (L) 并使用它们.否则它不起作用.如果有人可以解释是否有任何类型的自动转换,那将会很棒,但在那之前只需使用:

It seems that you need to explicitly set numeric literals to long (L) and they use them. Otherwise it does not work. If anyone can explain if there is any kind of automatic conversion it will be awesome but until then simply use:

unsigned long seconds = 1000L; // !!! SEE THE CAPITAL "L" USED!!!
unsigned long minutes = seconds * 60;
unsigned long hours = minutes * 60; 

然后像往常一样简单地使用延迟(毫秒):

and then simply use delay(millisec) as usual:

delay(5 * minutes);

它对我有用.

这篇关于我的 Arduino 在等待 1 分钟后停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆