制作出来的实物图如下:
LED灯接PWM输出功能的IO口3,5,6,9,10,11.
调速电位器中间抽头接A0口,用于控制流水灯的流动速度。
代码如下:
- int i, j, vol;
- unsigned char pin[] = {3, 5, 6, 9, 10, 11};
- unsigned int light[] = {0, 60, 120, 200, 255, 160, 50};
- void setup() {}
- void loop() {
- vol = analogRead(0);
- for (i = 0; i < 6; i++) {
- analogWrite(pin[i], light[j]);
- j++; if (j > 6) j = 0;
- delay(vol / 5);
- }
- }
复制代码
|