arduino 停止程序_我的Arduino 1分钟后停止等待

bd96500e110b49cbb3cd949968f18be7.png

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.

Here is the code

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.

Any idea?

解决方案

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);

It worked for me.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值