arduino渐变跑马灯的程序


#define STEPS 100
int ledPin[] ={5,6,7,8,9,10,11};    // LED connected to digital pin 9
int ledcount=4;
void setup() {
  for(int led=0;led<ledcount;led++)      //定义5-11号的引脚为输出;
  pinMode(ledPin[led],OUTPUT); 
}
void loop() {   //循环函数;
    fading();
}

void fading()
{
   for(int led=0; led<ledcount;led++)
  {
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {    //渐渐变亮;
    // sets the value (range from 0 to 255):
    analogWrite(ledPin[led], fadeValue);   //向定义的引脚写入一个模拟电压值;
    // wait for 30 milliseconds to see the dimming effect
    delay(10);
  }
  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {//由亮变暗;
    // sets the value (range from 0 to 255):
    analogWrite(ledPin[led], fadeValue);  
    // wait for 30 milliseconds to see the dimming effect
    delay(10);
  }
  }
}

你可能感兴趣的:(C语言,跑马灯,arduino)