3 * Very simple demonstration of the PiGlow board.
4 * This uses the piGlow devLib.
6 * Copyright (c) 2013 Gordon Henderson.
7 ***********************************************************************
8 * This file is part of wiringPi:
9 * https://projects.drogon.net/raspberry-pi/wiringpi/
11 * wiringPi is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * wiringPi is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************
32 # define FALSE (!TRUE)
38 static void failUsage (void)
40 fprintf (stderr, "Usage examples:\n") ;
41 fprintf (stderr, " piglow off # All off\n") ;
42 fprintf (stderr, " piglow red 50 # Light the 3 red LEDs to 50%%\n") ;
43 fprintf (stderr, " colours are: red, yellow, orange, green, blue and white\n") ;
44 fprintf (stderr, " piglow all 75 # Light all to 75%%\n") ;
45 fprintf (stderr, " piglow leg 0 25 # Light leg 0 to 25%%\n") ;
46 fprintf (stderr, " piglow ring 3 100 # Light ring 3 to 100%%\n") ;
47 fprintf (stderr, " piglow led 2 5 100 # Light the single LED on Leg 2, ring 5 to 100%%\n") ;
52 static int getPercent (char *typed)
56 percent = atoi (typed) ;
57 if ((percent < 0) || (percent > 100))
59 fprintf (stderr, "piglow: percent value out of range\n") ;
62 return (percent * 255) / 100 ;
68 * Our little demo prgoram
69 *********************************************************************************
72 int main (int argc, char *argv [])
77 // Always initialise wiringPi:
78 // Use the Sys method if you don't need to run as root
82 // Initialise the piGlow devLib
89 if ((argc == 2) && (strcasecmp (argv [1], "off") == 0))
91 for (leg = 0 ; leg < 3 ; ++leg)
98 percent = getPercent (argv [2]) ;
100 /**/ if (strcasecmp (argv [1], "red") == 0)
101 piGlowRing (PIGLOW_RED, percent) ;
102 else if (strcasecmp (argv [1], "yellow") == 0)
103 piGlowRing (PIGLOW_YELLOW, percent) ;
104 else if (strcasecmp (argv [1], "orange") == 0)
105 piGlowRing (PIGLOW_ORANGE, percent) ;
106 else if (strcasecmp (argv [1], "green") == 0)
107 piGlowRing (PIGLOW_GREEN, percent) ;
108 else if (strcasecmp (argv [1], "blue") == 0)
109 piGlowRing (PIGLOW_BLUE, percent) ;
110 else if (strcasecmp (argv [1], "white") == 0)
111 piGlowRing (PIGLOW_WHITE, percent) ;
112 else if (strcasecmp (argv [1], "all") == 0)
113 for (ring = 0 ; ring < 6 ; ++ring)
114 piGlowRing (ring, percent) ;
117 fprintf (stderr, "piglow: invalid colour\n") ;
118 exit (EXIT_FAILURE) ;
125 /**/ if (strcasecmp (argv [1], "leg") == 0)
127 leg = atoi (argv [2]) ;
128 if ((leg < 0) || (leg > 2))
130 fprintf (stderr, "piglow: leg value out of range\n") ;
131 exit (EXIT_FAILURE) ;
133 percent = getPercent (argv [3]) ;
134 piGlowLeg (leg, percent) ;
136 else if (strcasecmp (argv [1], "ring") == 0)
138 ring = atoi (argv [2]) ;
139 if ((ring < 0) || (ring > 5))
141 fprintf (stderr, "piglow: ring value out of range\n") ;
142 exit (EXIT_FAILURE) ;
144 percent = getPercent (argv [3]) ;
145 piGlowRing (ring, percent) ;
152 if (strcasecmp (argv [1], "led") != 0)
155 leg = atoi (argv [2]) ;
156 if ((leg < 0) || (leg > 2))
158 fprintf (stderr, "piglow: leg value out of range\n") ;
159 exit (EXIT_FAILURE) ;
161 ring = atoi (argv [3]) ;
162 if ((ring < 0) || (ring > 5))
164 fprintf (stderr, "piglow: ring value out of range\n") ;
165 exit (EXIT_FAILURE) ;
167 percent = getPercent (argv [4]) ;
168 piGlow1 (leg, ring, percent) ;