chiark / gitweb /
Added software PWM module into wiringPi - library code
[wiringPi.git] / examples / softPwm.c
1
2 #include <stdio.h>
3 #include <errno.h>
4 #include <string.h>
5
6 #include <wiringPi.h>
7 #include <softPwm.h>
8
9 #define RANGE           100
10 #define NUM_LEDS         12
11
12 int ledMap [NUM_LEDS] = { 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13 } ;
13
14 int values [NUM_LEDS] = { 0, 17, 32, 50, 67, 85, 100, 85, 67, 50, 32, 17 } ;
15
16 int main ()
17 {
18   int i, j ;
19
20   if (wiringPiSetup () == -1)
21   {
22     fprintf (stdout, "oops: %s\n", strerror (errno)) ;
23     return 1 ;
24   }
25
26   for (i = 0 ; i < NUM_LEDS ; ++i)
27   {
28     softPwmCreate (ledMap [i], 0, RANGE) ;
29     printf ("%3d, %3d, %3d\n", i, ledMap [i], values [i]) ;
30   }
31
32   for (;;)
33   {
34     for (i = 0 ; i < NUM_LEDS ; ++i)
35       softPwmWrite (ledMap [i], values [i]) ;
36
37     delay (50) ;
38
39     i = values [0] ;
40     for (j = 0 ; j < NUM_LEDS - 1 ; ++j)
41       values [j] = values [j + 1] ;
42     values [NUM_LEDS - 1] = i ;
43   }
44 }