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 ***********************************************************************
33 #define PIGLOW_BASE 533
37 * keypressed: clearKeypressed:
38 * Simple but effective ways to tell if the enter key has been pressed
39 *********************************************************************************
42 static int keypressed (void)
46 polls.fd = fileno (stdin) ;
47 polls.events = POLLIN ;
49 return poll (&polls, 1, 0) != 0 ;
52 static void clearKeypressed (void)
61 * Pulses the LED at position leg, ring from off to a max. value,
63 *********************************************************************************
66 static void pulseLed (int leg, int ring)
70 for (i = 0 ; i < 140 ; ++i)
72 piGlow1 (leg, ring, i) ;
76 for (i = 140 ; i >= 0 ; --i)
78 piGlow1 (leg, ring, i) ;
85 * Same as above, but a whole leg at a time
86 *********************************************************************************
89 static void pulseLeg (int leg)
93 for (i = 0 ; i < 140 ; ++i)
95 piGlowLeg (leg, i) ; delay (1) ;
98 for (i = 140 ; i >= 0 ; --i)
100 piGlowLeg (leg, i) ; delay (1) ;
107 * Same as above, but a whole ring at a time
108 *********************************************************************************
111 static void pulseRing (int ring)
115 for (i = 0 ; i < 140 ; ++i)
117 piGlowRing (ring, i) ; delay (1) ;
120 for (i = 140 ; i >= 0 ; --i)
122 piGlowRing (ring, i) ; delay (1) ;
129 * Our little demo prgoram
130 *********************************************************************************
138 // Always initialise wiringPi:
139 // Use the Sys method if you don't need to run as root
141 wiringPiSetupSys () ;
143 // Initialise the piGlow devLib with our chosen pin base
145 piGlowSetup (PIGLOW_BASE) ;
147 // LEDs, one at a time
149 printf ("LEDs, one at a time\n") ;
150 for (; !keypressed () ;)
151 for (leg = 0 ; leg < 3 ; ++leg)
153 for (ring = 0 ; ring < 6 ; ++ring)
155 pulseLed (leg, ring) ;
164 // Rings, one at a time
166 printf ("Rings, one at a time\n") ;
167 for (; !keypressed () ;)
168 for (ring = 0 ; ring < 6 ; ++ring)
176 // Legs, one at a time
178 printf ("Legs, one at a time\n") ;
179 for (; !keypressed () ;)
180 for (leg = 0 ; leg < 3 ; ++leg)
190 // Sequence - alternating rings, legs and random
192 printf ("Sequence now\n") ;
194 for (; !keypressed () ;)
196 for (i = 0 ; i < 20 ; ++i)
197 for (leg = 2 ; leg >= 0 ; --leg)
199 piGlowLeg (leg, 100) ;
204 for (i = 0 ; i < 20 ; ++i)
205 for (ring = 5 ; ring >= 0 ; --ring)
207 piGlowRing (ring, 100) ;
209 piGlowRing (ring, 0) ;
212 for (i = 0 ; i < 1000 ; ++i)
214 leg = random () % 3 ;
215 ring = random () % 6 ;
216 piGlow1 (leg, ring, random () % 256) ;
218 piGlow1 (leg, ring, 0) ;