3 * Simple test for the PiFace interface board.
5 * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
6 ***********************************************************************
7 * This file is part of wiringPi:
8 * https://projects.drogon.net/raspberry-pi/wiringpi/
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.
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.
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 ***********************************************************************
36 * Play middle A (on the relays - yea!)
37 *********************************************************************************
40 static void middleA (void)
46 next = micros () + 1136 ;
47 digitalWrite (PIFACE + 0, 0) ;
48 digitalWrite (PIFACE + 1, 0) ;
49 while (micros () < next)
50 delayMicroseconds (1) ;
52 next = micros () + 1137 ;
53 digitalWrite (PIFACE + 0, 1) ;
54 digitalWrite (PIFACE + 1, 1) ;
55 while (micros () < next)
56 delayMicroseconds (1) ;
62 int main (int argc, char *argv [])
64 int bpm, msPerBeat, state = 0 ;
67 printf ("Raspberry Pi PiFace Metronome\n") ;
68 printf ("=============================\n") ;
72 wiringPiSetupSys () ; // Needed for timing functions
73 piFaceSetup (PIFACE) ;
77 printf ("Usage: %s <beates per minute>\n", argv [0]) ;
81 if (strcmp (argv [1], "a") == 0)
84 bpm = atoi (argv [1]) ;
86 if ((bpm < 40) || (bpm > 208))
88 printf ("%s range is 40 through 208 beats per minute\n", argv [0]) ;
92 msPerBeat = 60000 / bpm ;
95 // Put some random LED pairs up for a few seconds, then blank ...
99 end = millis () + msPerBeat ;
101 digitalWrite (PIFACE + 0, state) ;
102 digitalWrite (PIFACE + 1, state) ;
104 while (millis () < end)
105 delayMicroseconds (500) ;