chiark / gitweb /
Added software PWM module into wiringPi - library code
[wiringPi.git] / examples / gertboard.c
1
2 /*
3  * gertboard.c:
4  *      Simple test for the SPI bus on the Gertboard
5  *
6  *      Hardware setup:
7  *              D/A port 0 jumpered to A/D port 0.
8  *
9  *      We output a sine wave on D/A port 0 and sample A/D port 0. We then
10  *      copy this value to D/A port 1 and use a 'scope on both D/A ports
11  *      to check all's well.
12  *
13  */
14
15 #include <stdio.h>
16 #include <stdint.h>
17 //#include <stdlib.h>
18 #include <math.h>
19
20 #include <wiringPi.h>
21 #include <gertboard.h>
22
23 int main (void)
24 {
25   int    angle ;
26   int      h1 ;
27   uint32_t x1 ;
28
29   printf ("Raspberry Pi Gertboard SPI test program\n") ;
30
31   if (gertboardSPISetup () == -1)
32     return 1 ;
33
34   for (;;)
35   {
36     for (angle = 0 ; angle < 360 ; ++angle)
37     {
38       h1 = (int)rint (sin ((double)angle * M_PI / 180.0) * 127.0 + 128.0) ;
39       gertboardAnalogWrite (0, h1) ;
40
41       x1 = gertboardAnalogRead (0) ;
42       gertboardAnalogWrite (1, x1 >> 2) ;       // 10-bit A/D, 8-bit D/A
43     }
44   }
45
46   return 0 ;
47 }