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 # define FALSE (!TRUE)
42 * keypressed: clearKeypressed:
43 * Simple but effective ways to tell if the enter key has been pressed
44 *********************************************************************************
47 static int keypressed (void)
51 polls.fd = fileno (stdin) ;
52 polls.events = POLLIN ;
54 return poll (&polls, 1, 0) != 0 ;
57 static void clearKeypressed (void)
66 * Pulses the LED at position leg, ring from off to a max. value,
68 *********************************************************************************
71 static void pulseLed (int leg, int ring)
75 for (i = 0 ; i < 140 ; ++i)
77 piGlow1 (leg, ring, i) ;
81 for (i = 140 ; i >= 0 ; --i)
83 piGlow1 (leg, ring, i) ;
90 * Same as above, but a whole leg at a time
91 *********************************************************************************
94 static void pulseLeg (int leg)
98 for (i = 0 ; i < 140 ; ++i)
100 piGlowLeg (leg, i) ; delay (1) ;
103 for (i = 140 ; i >= 0 ; --i)
105 piGlowLeg (leg, i) ; delay (1) ;
112 * Same as above, but a whole ring at a time
113 *********************************************************************************
116 static void pulseRing (int ring)
120 for (i = 0 ; i < 140 ; ++i)
122 piGlowRing (ring, i) ; delay (1) ;
125 for (i = 140 ; i >= 0 ; --i)
127 piGlowRing (ring, i) ; delay (1) ;
133 static int legSequence [] =
141 #define RING_STEPS 16
143 static int ringSequence [] =
165 * Our little demo prgoram
166 *********************************************************************************
172 int step, ring, leg ;
174 // Always initialise wiringPi:
175 // Use the Sys method if you don't need to run as root
177 wiringPiSetupSys () ;
179 // Initialise the piGlow devLib with our chosen pin base
183 // LEDs, one at a time
185 printf ("LEDs, one at a time\n") ;
186 for (; !keypressed () ;)
187 for (leg = 0 ; leg < 3 ; ++leg)
189 for (ring = 0 ; ring < 6 ; ++ring)
191 pulseLed (leg, ring) ;
200 // Rings, one at a time
202 printf ("Rings, one at a time\n") ;
203 for (; !keypressed () ;)
204 for (ring = 0 ; ring < 6 ; ++ring)
212 // Legs, one at a time
214 printf ("Legs, one at a time\n") ;
215 for (; !keypressed () ;)
216 for (leg = 0 ; leg < 3 ; ++leg)
226 // Sequence - alternating rings, legs and random
228 printf ("Sequence now\n") ;
229 for (; !keypressed () ;)
231 for (i = 0 ; i < 20 ; ++i)
232 for (step = 0 ; step < LEG_STEPS ; ++step)
234 for (leg = 0 ; leg < 3 ; ++leg)
235 piGlowLeg (leg, legSequence [step * 3 + leg]) ;
239 for (i = 0 ; i < 10 ; ++i)
240 for (step = 0 ; step < RING_STEPS ; ++step)
242 for (ring = 0 ; ring < 6 ; ++ring)
243 piGlowRing (ring, ringSequence [step * 6 + ring]) ;
247 for (i = 0 ; i < 1000 ; ++i)
249 leg = random () % 3 ;
250 ring = random () % 6 ;
251 piGlow1 (leg, ring, random () % 256) ;
253 piGlow1 (leg, ring, 0) ;