chiark / gitweb /
Quite a few changes here.
[wiringPi.git] / examples / piface.c
1 /*
2  * piFace.c:
3  *      Simple test for the PiFace interface board.
4  *
5  *      Read the buttons and output the same to the LEDs
6  *
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/
11  *
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.
16  *
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.
21  *
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  ***********************************************************************
25  */
26
27 #include <wiringPi.h>
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <stdint.h>
32
33 int outputs [4] = { 0,0,0,0 } ;
34
35 void scanButton (int button)
36 {
37   if (digitalRead (button) == LOW)
38   {
39     outputs [button] ^= 1 ;
40     digitalWrite (button, outputs [button]) ;
41   }
42
43   while (digitalRead (button) == LOW)
44     delay (1) ;
45 }
46
47
48 int main (void)
49 {
50   int pin, button ;
51
52   printf ("Raspberry Pi wiringPiFace test program\n") ;
53
54   if (wiringPiSetupPiFace () == -1)
55     exit (1) ;
56
57 // Enable internal pull-ups
58
59   for (pin = 0 ; pin < 8 ; ++pin)
60     pullUpDnControl (pin, PUD_UP) ;
61
62
63   for (;;)
64   {
65     for (button = 0 ; button < 4 ; ++button)
66       scanButton (button) ;
67     delay (1) ;
68   }
69
70   return 0 ;
71 }