5448| 0
|
[求助] 流水灯出现问题 |
初学Arduino,在练习流水灯的时候遇到了问题 const int Nbrleds = 6; const int ledPins[] = {3,5,6,9,10,11}; const int wait = 35; const int top = 40; const int mid = 20; const int bom = 10; void setup(){ for (int led = 0;led < Nbrleds;led++) {pinMode(ledPins[led],OUTPUT);} } void loop(){ for (int led = 0;led<Nbrleds - 1;led++) { analogWrite(ledPins[led],top); delay(wait); analogWrite(ledPins[led+1],top); analogWrite(ledPins[led],mid); delay(wait); analogWrite(ledPins[led+2],top); analogWrite(ledPins[led+1],mid); analogWrite(ledPins[led],bom); delay(wait); digitalWrite(ledPins[led],LOW); delay(wait*3); } for (int led = Nbrleds - 1;led > 0;led--) { analogWrite(ledPins[led],top); delay(wait); analogWrite(ledPins[led - 1],top); analogWrite(ledPins[led],mid); delay(wait); analogWrite(ledPins[led - 2],top); analogWrite(ledPins[led - 1],mid); analogWrite(ledPins[led],bom); delay(wait); digitalWrite(ledPins[led],LOW); delay(wait*3); } } 想用pmw实现拖尾效果,期初程序运行没有问题,灯可以正常流动,大概10次之后10、9灯就不亮了。又过了几次循环,11、5、3灯变成了常亮。不知道哪里出现的问题,请各位大神指点,谢谢 |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed