chiark / gitweb /
Merge branch 'master' of git.drogon.net:projects/wiringPi
[wiringPi.git] / examples / piface.c
1
2 /*
3  * piface.c:
4  *      Simple test for the PiFace
5  *
6  *      Read the buttons and output the same to the LEDs
7  */
8
9 #include <wiringPi.h>
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <stdint.h>
14
15 int outputs [4] = { 0,0,0,0 } ;
16
17 void scanButton (int button)
18 {
19   if (digitalRead (button) == LOW)
20   {
21     outputs [button] ^= 1 ;
22     digitalWrite (button, outputs [button]) ;
23   }
24
25   while (digitalRead (button) == LOW)
26     delay (1) ;
27 }
28
29
30 int main (void)
31 {
32   int pin, button ;
33
34   printf ("Raspberry Pi wiringPiFace test program\n") ;
35
36   if (wiringPiSetupPiFace () == -1)
37     exit (1) ;
38
39 // Enable internal pull-ups
40
41   for (pin = 0 ; pin < 8 ; ++pin)
42     pullUpDnControl (pin, PUD_UP) ;
43
44
45   for (;;)
46   {
47     for (button = 0 ; button < 4 ; ++button)
48       scanButton (button) ;
49     delay (1) ;
50   }
51
52   return 0 ;
53 }