Blinking LED

Raspberry Pi project #1, the blinking of an LED using C and the wiringPi library. I know this isn’t necessarily anything special but I wanted to record my little projects and what better place to start than by building a simple circuit and making a green LED blink on and off.

Requirements:
WiringPi library

#include <stdio.h>
#include <wiringPi.h>

// Bulid: gcc -o blink blink.c -lwiringPi
// Use Broadcom numbering PIN 11 on Pi
#define LED 0     

int main (void)
{
    printf("Raspberry Pi BLINK\n");

    wiringPiSetup ();
    pinMode (LED, OUTPUT);

    digitalWrite (LED, 0); 
    
    int i;

    for (i = 0; i < 10; i++)
    {
        printf("Blink %d\n", i);
        digitalWrite (LED, 1);  // Turn ON LED
        delay (500);            // Wait half a second
        digitalWrite (LED, 0);  // Turn OFF LED
        delay (500);            // Wait half a second
    }
    
    return 0;
}
This entry was posted in C, Programming. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *