3 * Simple test for the PiFace interface board.
5 * Read the buttons and output the same to the LEDs
7 * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
8 ***********************************************************************
9 * This file is part of wiringPi:
10 * https://projects.drogon.net/raspberry-pi/wiringpi/
12 * wiringPi is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * wiringPi is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
24 ***********************************************************************
32 int outputs [4] = { 0,0,0,0 } ;
34 // Use 200 as the pin-base for the PiFace board
36 #define PIFACE_BASE 200
41 * Read the guiven button - if it's pressed, then flip the state
42 * of the correspoinding output pin
43 *********************************************************************************
46 void scanButton (int button)
48 if (digitalRead (PIFACE_BASE + button) == LOW)
50 outputs [button] ^= 1 ;
51 digitalWrite (PIFACE_BASE + button, outputs [button]) ;
52 printf ("Button %d pushed - output now: %s\n",
53 button, (outputs [button] == 0) ? "Off" : "On") ;
56 while (digitalRead (PIFACE_BASE + button) == LOW)
63 *********************************************************************************
70 printf ("Raspberry Pi wiringPi + PiFace test program\n") ;
71 printf ("===========================================\n") ;
74 "This program reads the buttons and uses them to toggle the first 4\n"
75 "outputs. Push a button once to turn an output on, and push it again to\n"
76 "turn it off again.\n\n") ;
78 // Always initialise wiringPi. Use wiringPiSys() if you don't need
79 // (or want) to run as root
83 piFaceSetup (PIFACE_BASE) ;
85 // Enable internal pull-ups & start with all off
87 for (pin = 0 ; pin < 8 ; ++pin)
89 pullUpDnControl (PIFACE_BASE + pin, PUD_UP) ;
90 digitalWrite (PIFACE_BASE + pin, 0) ;
93 // Loop, scanning the buttons
97 for (button = 0 ; button < 4 ; ++button)