gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
Code a loop to keep an led blinking in c
- User
Code a loop to keep an led blinking in c
- Assistant
Sure! Below is an example code in C to keep an LED blinking using a loop:
#include <stdio.h> #include <wiringPi.h> #define LED_PIN 4 int main(void) { wiringPiSetup(); // Initialize WiringPi library pinMode(LED_PIN, OUTPUT); // Set LED_PIN as output // Loop to keep the LED blinking while(1) { digitalWrite(LED_PIN, HIGH); // Turn on the LED delay(1000); // Delay for 1 second digitalWrite(LED_PIN, LOW); // Turn off the LED delay(1000); // Delay for 1 second } return 0; }Make sure to replace
LED_PINwith the actual GPIO pin number connected to the LED. In the example above, pin 4 is used as an example. This code uses thewiringPilibrary for GPIO operations.When you run this code, the LED connected to the specified GPIO pin will blink at a 1-second interval.