问题参见代码中的注释,why always print 0?- //run horse light 2013.11.10
- byte ledPin[] = {5,6,7,8,9,10,11,12};
- int ledDelay = 65;
- int ledDirection = 1;
- int currentLed = 0;
- unsigned long changeTime;
- void setup(){
- Serial.begin(9600);
- for(int i = 0;i<8;i++){
- pinMode(ledPin[i],OUTPUT);
- }
- changeTime = millis();
- }
- void loop(){
- //Serial.println("hello");
- int ival = millis()-changeTime;
- Serial.println(ival);//why always print 0?
- if((millis()-changeTime)>ledDelay){
- Serial.println("hello");
- changeLights();
- }
- changeTime = millis();
- }
- void changeLights(){
- for(int i = 0;i < 8;i++){
- digitalWrite(ledPin[i],LOW);
- }
- digitalWrite(currentLed,HIGH);
- currentLed += ledDirection;
-
- if(currentLed == 9){
- ledDirection = -1;
- }
- if(currentLed == 0){
- ledDirection = 1;
- }
- }
复制代码 |