Statistics
| Branch: | Revision:

ddr4s / fw / wiringPi / devLib / piGlow.c @ 32:cadb9025f1e0

History | View | Annotate | Download (2.91 KB)

1
/*
2
 * piGlow.c:
3
 *        Easy access to the Pimoroni PiGlow board.
4
 *
5
 * Copyright (c) 2013 Gordon Henderson.
6
 ***********************************************************************
7
 * This file is part of wiringPi:
8
 *        https://projects.drogon.net/raspberry-pi/wiringpi/
9
 *
10
 *    wiringPi is free software: you can redistribute it and/or modify
11
 *    it under the terms of the GNU Lesser General Public License as published by
12
 *    the Free Software Foundation, either version 3 of the License, or
13
 *    (at your option) any later version.
14
 *
15
 *    wiringPi is distributed in the hope that it will be useful,
16
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *    GNU Lesser General Public License for more details.
19
 *
20
 *    You should have received a copy of the GNU Lesser General Public License
21
 *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.
22
 ***********************************************************************
23
 */
24

    
25
#include <wiringPi.h>
26
#include <sn3218.h>
27

    
28
#include "piGlow.h"
29

    
30
#define        PIGLOW_BASE        577
31

    
32
static int leg0 [6] = {  6,  7,  8,  5,  4,  9 } ;
33
static int leg1 [6] = { 17, 16, 15, 13, 11, 10 } ;
34
static int leg2 [6] = {  0,  1,  2,  3, 14, 12 } ;
35

    
36

    
37
/*
38
 * piGlow1:
39
 *        Light up an individual LED
40
 *********************************************************************************
41
 */
42

    
43
void piGlow1 (const int leg, const int ring, const int intensity)
44
{
45
  int *legLeds ;
46

    
47
  if ((leg  < 0) || (leg  > 2)) return ;
48
  if ((ring < 0) || (ring > 5)) return ;
49

    
50
  /**/ if (leg == 0)
51
    legLeds = leg0 ;
52
  else if (leg == 1)
53
    legLeds = leg1 ;
54
  else
55
    legLeds = leg2 ;
56

    
57
  analogWrite (PIGLOW_BASE + legLeds [ring], intensity) ;
58
}
59

    
60
/*
61
 * piGlowLeg:
62
 *        Light up all 6 LEDs on a leg
63
 *********************************************************************************
64
 */
65

    
66
void piGlowLeg (const int leg, const int intensity)
67
{
68
  int  i ;
69
  int *legLeds ;
70

    
71
  if ((leg < 0) || (leg > 2))
72
    return ;
73

    
74
  /**/ if (leg == 0)
75
    legLeds = leg0 ;
76
  else if (leg == 1)
77
    legLeds = leg1 ;
78
  else
79
    legLeds = leg2 ;
80

    
81
  for (i = 0 ; i < 6 ; ++i)
82
    analogWrite (PIGLOW_BASE + legLeds [i], intensity) ;
83
}
84

    
85

    
86
/*
87
 * piGlowRing:
88
 *        Light up 3 LEDs in a ring. Ring 0 is the outermost, 5 the innermost
89
 *********************************************************************************
90
 */
91

    
92
void piGlowRing (const int ring, const int intensity)
93
{
94
  if ((ring < 0) || (ring > 5))
95
    return ;
96

    
97
  analogWrite (PIGLOW_BASE + leg0 [ring], intensity) ;
98
  analogWrite (PIGLOW_BASE + leg1 [ring], intensity) ;
99
  analogWrite (PIGLOW_BASE + leg2 [ring], intensity) ;
100
}
101

    
102
/*
103
 * piGlowSetup:
104
 *        Initialise the board & remember the pins we're using
105
 *********************************************************************************
106
 */
107

    
108
void piGlowSetup (int clear)
109
{
110
  sn3218Setup (PIGLOW_BASE) ;
111

    
112
  if (clear)
113
  {
114
    piGlowLeg (0, 0) ;
115
    piGlowLeg (1, 0) ;
116
    piGlowLeg (2, 0) ;
117
  }
118
}