guowenxue
2019-05-06 b9a783dac7d473d8dd2bc64ddade1823866f2a23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*********************************************************************************
 *      Copyright:  (C) 2018 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  led.c
 *    Description:  This file is used to control RGB 3-colours LED
 *
 *     pi@raspberrypi:~ $ gpio readall show BCM and wPi pinmap  
 *
 *                 LED      BCM           wPi 
 *                  G ---- GPIO.13  ---- GPIO.23
 *                  R ---- GPIO.19  ---- GPIO.24    
 *                  B ---- GPIO.26  ---- GPIO.25
 *                  I ---- GND      ----
 *                 
 *        Version:  1.0.0(2018/10/14)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "2018/10/14 12:13:26"
 *                 
 ********************************************************************************/
 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <string.h>
#include <time.h>
#include <errno.h>
 
#include <wiringPi.h>
#include "led.h"
 
void init_led(void)
{
    int         i;
 
    wiringPiSetup();
 
    for(i=0; i<LED_MAX; i++)
    {
               pinMode( led_gpio[i], OUTPUT );
    }
}
 
int turn_led(int which, int cmd)
{
    if( which<0 || which>=LED_MAX )
        return -1;
 
 
    if( OFF == cmd )
               digitalWrite (led_gpio[which], LOW);
    else
               digitalWrite (led_gpio[which], HIGH);
 
    return 0;
}