c语言依次点亮8个流水灯led代码
时间: 2023-04-05 22:04:44 浏览: 400
以下是一个简单的C语言程序,可以依次点亮8个流水灯LED:
```c
#include <stdio.h>
#include <wiringPi.h>
#define LED_PIN_1 0
#define LED_PIN_2 1
#define LED_PIN_3 2
#define LED_PIN_4 3
#define LED_PIN_5 4
#define LED_PIN_6 5
#define LED_PIN_7 6
#define LED_PIN_8 7
int main(void) {
wiringPiSetup();
pinMode(LED_PIN_1, OUTPUT);
pinMode(LED_PIN_2, OUTPUT);
pinMode(LED_PIN_3, OUTPUT);
pinMode(LED_PIN_4, OUTPUT);
pinMode(LED_PIN_5, OUTPUT);
pinMode(LED_PIN_6, OUTPUT);
pinMode(LED_PIN_7, OUTPUT);
pinMode(LED_PIN_8, OUTPUT);
while (1) {
digitalWrite(LED_PIN_1, HIGH);
delay(100);
digitalWrite(LED_PIN_1, LOW);
digitalWrite(LED_PIN_2, HIGH);
delay(100);
digitalWrite(LED_PIN_2, LOW);
digitalWrite(LED_PIN_3, HIGH);
delay(100);
digitalWrite(LED_PIN_3, LOW);
digitalWrite(LED_PIN_4, HIGH);
delay(100);
digitalWrite(LED_PIN_4, LOW);
digitalWrite(LED_PIN_5, HIGH);
delay(100);
digitalWrite(LED_PIN_5, LOW);
digitalWrite(LED_PIN_6, HIGH);
delay(100);
digitalWrite(LED_PIN_6, LOW);
digitalWrite(LED_PIN_7, HIGH);
delay(100);
digitalWrite(LED_PIN_7, LOW);
digitalWrite(LED_PIN_8, HIGH);
delay(100);
digitalWrite(LED_PIN_8, LOW);
}
return 0;
}
```
阅读全文