7.Run LED program

Firstly you need install the library

Then you need connect the GPIO.25,GPIO.26,GPIO.27,GPIO.28 to one port of LED,the other one port of LED is connected to GND

On the Terminal, enter:
sudo wget http://www.spotpear.com/download/raspberry-pi-other/DVK512.tar.gz

sudo tar xvf DVK512.tar.gz

WiringPi

  • cd DVK512/LED/wiringPi/
  • sudo make
  • sudo ./led
    Then You will see the LED flashing, Press Ctrl+C to end the program
  • Code:
    -----------------------------------------------------------------------------------
    #include<wiringPi.h> //include the library
    char LED[]={25,26,27,28}; //define the LED wPi
    unsigned char i;
    int main(void)
    {
    wiringPiSetup();
    for(i=0;i<4;i++)
    {
    pinMode (LED[i],OUTPUT) ;//make the LED PIN output
    }
    while(1)
    {
    for(i=0;i<4;i++)
    {
    digitalWrite (LED[i], 1) ;//make the LED PIN output HIGH
    delay (200); //delay 200ms high
    digitalWrite (LED[i], 0) ;//make the LED PIN output LOW
    delay (200);//delay 200ms low
    }
    }
    }
    -----------------------------------------------------------------------------------

Bcm2835 C

  • cd DVK512/LED/bcm2835/
  • sudo make
  • sudo ./led
    Then You will see the LED flashing, Press Ctrl+C to end the program
  • Code:
    -----------------------------------------------------------------------------------
    #include <bcm2835.h>
    char LED[] = {26,12,16,20}; //define the LED BCM
    unsigned char i;
    int main(int argc, char **argv)
    {
    if (!bcm2835_init())return 1;
    for(i = 0; i < 4; i++)
    {
    bcm2835_gpio_fsel(LED[i], BCM2835_GPIO_FSEL_OUTP);
    }
    while (1)
    {
    for(i = 0; i < 4; i++)
    {
    bcm2835_gpio_write(LED[i], HIGH);
    bcm2835_delay(500);
    bcm2835_gpio_write(LED[i], LOW);
    bcm2835_delay(500);
    }
    }
    bcm2835_close();
    return 0;
    }
    -----------------------------------------------------------------------------------

Python

  • cd DVK512/LED/python/
  • sudo python blink.py
    Then You will see the LED flashing, Press Ctrl+C to end the program
  • Code:
    -----------------------------------------------------------------------------------
  • #!/usr/bin/python
    # -*- coding:utf-8 -*-
    import RPi.GPIO as GPIO
    import time

    #define the LED BCM
    LED = [26,12,16,20]
    GPIO.setmode(GPIO.BCM)
    #define a easy way to set pin value
    def ledWrite(pin,value):
            if value:
                    GPIO.output(pin,GPIO.HIGH)
            else:
                    GPIO.output(pin,GPIO.LOW)
    for i in LED:
            GPIO.setup(i,GPIO.OUT)
            ledWrite(i,0)
    try:
            while True:
                    for i in LED:
                            ledWrite(i,1)
                            time.sleep(0.5)
                            ledWrite(i,0)
                            time.sleep(0.5)
    except:
            print("except")
            GPIO.cleanup()
    -----------------------------------------------------------------------------------