chiark / gitweb /
Slight change to the gpio program to fix SPI buffer size when loading
[wiringPi.git] / examples / blink12.c
1 /*
2  * blink12.c:
3  *      Simple sequence over the first 12 GPIO pins - LEDs
4  *      Aimed at the Gertboard, but it's fairly generic.
5  *
6  * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
7  ***********************************************************************
8  * This file is part of wiringPi:
9  *      https://projects.drogon.net/raspberry-pi/wiringpi/
10  *
11  *    wiringPi is free software: you can redistribute it and/or modify
12  *    it under the terms of the GNU Lesser General Public License as published by
13  *    the Free Software Foundation, either version 3 of the License, or
14  *    (at your option) any later version.
15  *
16  *    wiringPi is distributed in the hope that it will be useful,
17  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *    GNU Lesser General Public License for more details.
20  *
21  *    You should have received a copy of the GNU Lesser General Public License
22  *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.
23  ***********************************************************************
24  */
25
26 #include <stdio.h>
27 #include <wiringPi.h>
28
29 // Simple sequencer data
30 //      Triplets of LED, On/Off and delay
31
32 int data [] =
33 {
34             0, 1, 1,
35             1, 1, 1,
36   0, 0, 0,  2, 1, 1,
37   1, 0, 0,  3, 1, 1,
38   2, 0, 0,  4, 1, 1,
39   3, 0, 0,  5, 1, 1,
40   4, 0, 0,  6, 1, 1,
41   5, 0, 0,  7, 1, 1,
42   6, 0, 0, 11, 1, 1,
43   7, 0, 0, 10, 1, 1,
44  11, 0, 0, 13, 1, 1,
45  10, 0, 0, 12, 1, 1,
46  13, 0, 1,
47  12, 0, 1,
48
49   0, 0, 1,      // Extra delay
50
51 // Back again
52
53            12, 1, 1,
54            13, 1, 1,
55  12, 0, 0, 10, 1, 1,
56  13, 0, 0, 11, 1, 1,
57  10, 0, 0,  7, 1, 1,
58  11, 0, 0,  6, 1, 1,
59   7, 0, 0,  5, 1, 1,
60   6, 0, 0,  4, 1, 1,
61   5, 0, 0,  3, 1, 1,
62   4, 0, 0,  2, 1, 1,
63   3, 0, 0,  1, 1, 1,
64   2, 0, 0,  0, 1, 1,
65   1, 0, 1,
66   0, 0, 1,
67
68   0, 0, 1,      // Extra delay
69
70   0, 9, 0,      // End marker
71
72 } ;
73
74
75 int main (void)
76 {
77   int pin ;
78   int dataPtr ;
79   int l, s, d ;
80
81   printf ("Raspberry Pi - 12-LED Sequence\n") ;
82   printf ("==============================\n") ;
83   printf ("\n") ;
84   printf ("Connect LEDs up to the first 8 GPIO pins, then pins 11, 10, 13, 12 in\n") ;
85   printf ("    that order, then sit back and watch the show!\n") ;
86
87   wiringPiSetup () ;
88
89   for (pin = 0 ; pin < 14 ; ++pin)
90     pinMode (pin, OUTPUT) ;
91
92   dataPtr = 0 ;
93
94   for (;;)
95   {
96     l = data [dataPtr++] ;      // LED
97     s = data [dataPtr++] ;      // State
98     d = data [dataPtr++] ;      // Duration (10ths)
99
100     if (s == 9)                 // 9 -> End Marker
101     {
102       dataPtr = 0 ;
103       continue ;
104     }
105
106     digitalWrite (l, s) ;
107     delay        (d * 100) ;
108   }
109
110   return 0 ;
111 }