User Manual
22
Step 2: Use nano or other code edit tools to open led.c, write down the following code and
save it.
#include <wiringPi.h>
#include <stdio.h>
#define LEDPin 0
int main(void)
{
if(wiringPiSetup() == -1){//when the wiringPi initialization fails, print
message to the screen.
printf("setup wiringPi failed !");
return 1;
}
pinMode(LEDPin, OUTPUT);
while(1){
digitalWrite(LEDPin, LOW); //led on
printf("led on...\n");
delay(500);
digitalWrite(LEDPin, HIGH); //led off
printf("...led off\n");
delay(500);
}
return 0;
}
Step 3: Compile
gcc led.c –o led –lwiringPi
Step 4: Run
sudo ./led
You should see the LED blinking. Press Ctrl+C to terminate the program.
For Python users (based on the RPi.GPIO python module):
Step 1: Create a Python file named led.py
touch led.py
Step 2: Use nano or other code edit tools to open led.py, write down the following code and
save it.
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time










