chiark / gitweb /
Tidying up some old debug
[wiringPi.git] / examples / test1.c
1
2 /*
3  * test1.c:
4  *      Simple test program to test the wiringPi functions
5  */
6
7 #include <wiringPi.h>
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <stdint.h>
12
13
14 // Simple sequencer data
15 //      Triplets of LED, On/Off and delay
16
17 uint8_t data [] =
18 {
19             0, 1, 1,
20             1, 1, 1,
21   0, 0, 0,  2, 1, 1,
22   1, 0, 0,  3, 1, 1,
23   2, 0, 0,  4, 1, 1,
24   3, 0, 0,  5, 1, 1,
25   4, 0, 0,  6, 1, 1,
26   5, 0, 0,  7, 1, 1,
27   6, 0, 1,
28   7, 0, 1,
29
30   0, 0, 1,      // Extra delay
31
32 // Back again
33
34             7, 1, 1,
35             6, 1, 1,
36   7, 0, 0,  5, 1, 1,
37   6, 0, 0,  4, 1, 1,
38   5, 0, 0,  3, 1, 1,
39   4, 0, 0,  2, 1, 1,
40   3, 0, 0,  1, 1, 1,
41   2, 0, 0,  0, 1, 1,
42   1, 0, 1,
43   0, 0, 1,
44
45   0, 0, 1,      // Extra delay
46
47   9, 9, 9,      // End marker
48
49 } ;
50
51
52 int main (void)
53 {
54   int pin ;
55   int dataPtr ;
56   int l, s, d ;
57
58   printf ("Raspberry Pi wiringPi test program\n") ;
59
60   if (wiringPiSetup () == -1)
61     exit (1) ;
62
63   for (pin = 0 ; pin < 8 ; ++pin)
64     pinMode (pin, OUTPUT) ;
65
66   pinMode (8, INPUT) ;  // Pin 8 SDA0 - Has on-board 2k2 pull-up resistor
67
68   dataPtr = 0 ;
69
70   for (;;)
71   {
72     l = data [dataPtr++] ;      // LED
73     s = data [dataPtr++] ;      // State
74     d = data [dataPtr++] ;      // Duration (10ths)
75
76     if ((l + s + d) == 27)
77     {
78       dataPtr = 0 ;
79       continue ;
80     }
81
82     digitalWrite (l, s) ;
83
84     if (digitalRead (8) == 0)   // Pressed as our switch shorts to ground
85       delay (d * 10) ;  // Faster!
86     else
87       delay (d * 100) ;
88   }
89
90   return 0 ;
91 }