wiringpi 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/ext/wiringpi/WiringPi/devLib/ds1302.c +240 -0
  3. data/ext/wiringpi/WiringPi/devLib/ds1302.h +44 -0
  4. data/ext/wiringpi/WiringPi/devLib/font.h +2577 -0
  5. data/ext/wiringpi/WiringPi/devLib/gertboard.c +164 -0
  6. data/ext/wiringpi/WiringPi/devLib/gertboard.h +45 -0
  7. data/ext/wiringpi/WiringPi/devLib/lcd.c +495 -0
  8. data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
  9. data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +673 -0
  10. data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
  11. data/ext/wiringpi/WiringPi/devLib/maxdetect.c +165 -0
  12. data/ext/wiringpi/{serial.h → WiringPi/devLib/maxdetect.h} +14 -15
  13. data/ext/wiringpi/WiringPi/devLib/piFace.c +112 -0
  14. data/ext/wiringpi/WiringPi/devLib/piFace.h +32 -0
  15. data/ext/wiringpi/WiringPi/devLib/piFaceOld.c +178 -0
  16. data/ext/wiringpi/WiringPi/devLib/piGlow.c +118 -0
  17. data/ext/wiringpi/WiringPi/devLib/piGlow.h +45 -0
  18. data/ext/wiringpi/WiringPi/devLib/piNes.c +113 -0
  19. data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
  20. data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
  21. data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
  22. data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
  23. data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
  24. data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
  25. data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
  26. data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
  27. data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
  28. data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
  29. data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
  30. data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
  31. data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
  32. data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
  33. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
  34. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
  35. data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
  36. data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
  37. data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
  38. data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
  39. data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
  40. data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
  41. data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
  42. data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
  43. data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
  44. data/ext/wiringpi/WiringPi/examples/header.h +23 -0
  45. data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
  46. data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
  47. data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
  48. data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
  49. data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
  50. data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
  51. data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
  52. data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
  53. data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
  54. data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
  55. data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
  56. data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
  57. data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
  58. data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
  59. data/ext/wiringpi/WiringPi/examples/rht03.c +69 -0
  60. data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
  61. data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
  62. data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
  63. data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
  64. data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
  65. data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
  66. data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
  67. data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
  68. data/ext/wiringpi/WiringPi/gpio/gpio.c +1351 -0
  69. data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
  70. data/ext/wiringpi/WiringPi/gpio/readall.c +334 -0
  71. data/ext/wiringpi/WiringPi/gpio/version.h +1 -0
  72. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +201 -0
  73. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
  74. data/ext/wiringpi/WiringPi/wiringPi/max31855.c +81 -0
  75. data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
  76. data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
  77. data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
  78. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
  79. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
  80. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
  81. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
  82. data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
  83. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
  84. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
  85. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +189 -0
  86. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
  87. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +236 -0
  88. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
  89. data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
  90. data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
  91. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
  92. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
  93. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
  94. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
  95. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +110 -0
  96. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
  97. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
  98. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
  99. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
  100. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
  101. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
  102. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
  103. data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
  104. data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
  105. data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
  106. data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
  107. data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +166 -0
  108. data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
  109. data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
  110. data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
  111. data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
  112. data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
  113. data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
  114. data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
  115. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2007 -0
  116. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +224 -0
  117. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +232 -0
  118. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
  119. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +136 -0
  120. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
  121. data/ext/wiringpi/{serial.c → WiringPi/wiringPi/wiringSerial.c} +38 -29
  122. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
  123. data/ext/wiringpi/{wiringShift.c → WiringPi/wiringPi/wiringShift.c} +3 -4
  124. data/ext/wiringpi/{wiringShift.h → WiringPi/wiringPi/wiringShift.h} +5 -5
  125. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +731 -0
  126. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
  127. data/ext/wiringpi/extconf.rb +7 -1
  128. data/ext/wiringpi/wiringpi_wrap.c +1741 -218
  129. data/lib/wiringpi.rb +24 -222
  130. data/lib/wiringpi/event.rb +21 -0
  131. data/lib/wiringpi/gpio.rb +139 -0
  132. data/lib/wiringpi/i2c.rb +26 -0
  133. data/lib/wiringpi/mcp23x17.rb +31 -0
  134. data/lib/wiringpi/serial.rb +49 -0
  135. data/lib/wiringpi/spi.rb +15 -0
  136. metadata +146 -22
  137. data/ext/wiringpi/wiringPi.c +0 -729
  138. data/ext/wiringpi/wiringPi.h +0 -69
@@ -0,0 +1,111 @@
1
+ /*
2
+ * metronome.c:
3
+ * Simple test for the PiFace interface board.
4
+ *
5
+ * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
6
+ ***********************************************************************
7
+ * This file is part of wiringPi:
8
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
9
+ *
10
+ * wiringPi is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU Lesser General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * wiringPi is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU Lesser General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU Lesser General Public License
21
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
22
+ ***********************************************************************
23
+ */
24
+
25
+ #include <stdio.h>
26
+ #include <stdlib.h>
27
+ #include <string.h>
28
+
29
+ #include <wiringPi.h>
30
+ #include <piFace.h>
31
+
32
+ #define PIFACE 200
33
+
34
+ /*
35
+ * middleA:
36
+ * Play middle A (on the relays - yea!)
37
+ *********************************************************************************
38
+ */
39
+
40
+ static void middleA (void)
41
+ {
42
+ unsigned int next ;
43
+
44
+ for (;;)
45
+ {
46
+ next = micros () + 1136 ;
47
+ digitalWrite (PIFACE + 0, 0) ;
48
+ digitalWrite (PIFACE + 1, 0) ;
49
+ while (micros () < next)
50
+ delayMicroseconds (1) ;
51
+
52
+ next = micros () + 1137 ;
53
+ digitalWrite (PIFACE + 0, 1) ;
54
+ digitalWrite (PIFACE + 1, 1) ;
55
+ while (micros () < next)
56
+ delayMicroseconds (1) ;
57
+
58
+ }
59
+ }
60
+
61
+
62
+ int main (int argc, char *argv [])
63
+ {
64
+ int bpm, msPerBeat, state = 0 ;
65
+ unsigned int end ;
66
+
67
+ printf ("Raspberry Pi PiFace Metronome\n") ;
68
+ printf ("=============================\n") ;
69
+
70
+ piHiPri (50) ;
71
+
72
+ wiringPiSetupSys () ; // Needed for timing functions
73
+ piFaceSetup (PIFACE) ;
74
+
75
+ if (argc != 2)
76
+ {
77
+ printf ("Usage: %s <beates per minute>\n", argv [0]) ;
78
+ exit (1) ;
79
+ }
80
+
81
+ if (strcmp (argv [1], "a") == 0)
82
+ middleA () ;
83
+
84
+ bpm = atoi (argv [1]) ;
85
+
86
+ if ((bpm < 40) || (bpm > 208))
87
+ {
88
+ printf ("%s range is 40 through 208 beats per minute\n", argv [0]) ;
89
+ exit (1) ;
90
+ }
91
+
92
+ msPerBeat = 60000 / bpm ;
93
+
94
+ // Main loop:
95
+ // Put some random LED pairs up for a few seconds, then blank ...
96
+
97
+ for (;;)
98
+ {
99
+ end = millis () + msPerBeat ;
100
+
101
+ digitalWrite (PIFACE + 0, state) ;
102
+ digitalWrite (PIFACE + 1, state) ;
103
+
104
+ while (millis () < end)
105
+ delayMicroseconds (500) ;
106
+
107
+ state ^= 1 ;
108
+ }
109
+
110
+ return 0 ;
111
+ }
@@ -0,0 +1,120 @@
1
+ /*
2
+ * motor.c:
3
+ * Use the PiFace board to demonstrate an H bridge
4
+ * circuit via the 2 relays.
5
+ * Then add on an external transsitor to help with PWM.
6
+ *
7
+ * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
8
+ ***********************************************************************
9
+ * This file is part of wiringPi:
10
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
11
+ *
12
+ * wiringPi is free software: you can redistribute it and/or modify
13
+ * it under the terms of the GNU Lesser General Public License as published by
14
+ * the Free Software Foundation, either version 3 of the License, or
15
+ * (at your option) any later version.
16
+ *
17
+ * wiringPi is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ * GNU Lesser General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU Lesser General Public License
23
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
24
+ ***********************************************************************
25
+ */
26
+
27
+ #include <wiringPi.h>
28
+ #include <piFace.h>
29
+ #include <softPwm.h>
30
+
31
+ #include <stdio.h>
32
+ #include <stdlib.h>
33
+ #include <stdint.h>
34
+
35
+ int outputs [2] = { 0,0 } ;
36
+
37
+ #define PIFACE_BASE 200
38
+ #define PWM_OUT_PIN 204
39
+ #define PWM_UP 202
40
+ #define PWM_DOWN 203
41
+
42
+ void scanButton (int button)
43
+ {
44
+ if (digitalRead (PIFACE_BASE + button) == LOW)
45
+ {
46
+ outputs [button] ^= 1 ;
47
+ digitalWrite (PIFACE_BASE + button, outputs [button]) ;
48
+ printf ("Button %d pushed - output now: %s\n",
49
+ button, (outputs [button] == 0) ? "Off" : "On") ;
50
+ }
51
+
52
+ while (digitalRead (PIFACE_BASE + button) == LOW)
53
+ delay (1) ;
54
+ }
55
+
56
+
57
+ int main (void)
58
+ {
59
+ int pin, button ;
60
+ int pwmValue = 0 ;
61
+
62
+ printf ("Raspberry Pi PiFace - Motor control\n") ;
63
+ printf ("==================================\n") ;
64
+ printf ("\n") ;
65
+ printf (
66
+ "This program is designed to be used with a motor connected to the relays\n"
67
+ "in an H-Bridge type configuration with optional speeed control via PWM.\n"
68
+ "\n"
69
+ "Use the leftmost buttons to turn each relay on and off, and the rigthmost\n"
70
+ "buttons to increase ot decrease the PWM output on the control pin (pin\n"
71
+ "4)\n\n") ;
72
+
73
+ wiringPiSetup () ;
74
+ piFaceSetup (PIFACE_BASE) ;
75
+ softPwmCreate (PWM_OUT_PIN, 100, 100) ;
76
+
77
+ // Enable internal pull-ups & start with all off
78
+
79
+ for (pin = 0 ; pin < 8 ; ++pin)
80
+ {
81
+ pullUpDnControl (PIFACE_BASE + pin, PUD_UP) ;
82
+ digitalWrite (PIFACE_BASE + pin, 0) ;
83
+ }
84
+
85
+ for (;;)
86
+ {
87
+ for (button = 0 ; button < 2 ; ++button)
88
+ scanButton (button) ;
89
+
90
+ if (digitalRead (PWM_UP) == LOW)
91
+ {
92
+ pwmValue += 10 ;
93
+ if (pwmValue > 100)
94
+ pwmValue = 100 ;
95
+
96
+ softPwmWrite (PWM_OUT_PIN, pwmValue) ;
97
+ printf ("PWM -> %3d\n", pwmValue) ;
98
+
99
+ while (digitalRead (PWM_UP) == LOW)
100
+ delay (5) ;
101
+ }
102
+
103
+ if (digitalRead (PWM_DOWN) == LOW)
104
+ {
105
+ pwmValue -= 10 ;
106
+ if (pwmValue < 0)
107
+ pwmValue = 0 ;
108
+
109
+ softPwmWrite (PWM_OUT_PIN, pwmValue) ;
110
+ printf ("PWM -> %3d\n", pwmValue) ;
111
+
112
+ while (digitalRead (PWM_DOWN) == LOW)
113
+ delay (5) ;
114
+ }
115
+
116
+ delay (5) ;
117
+ }
118
+
119
+ return 0 ;
120
+ }
@@ -0,0 +1,194 @@
1
+ /*
2
+ * reaction.c:
3
+ * Simple test for the PiFace interface board.
4
+ *
5
+ * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
6
+ ***********************************************************************
7
+ * This file is part of wiringPi:
8
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
9
+ *
10
+ * wiringPi is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU Lesser General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * wiringPi is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU Lesser General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU Lesser General Public License
21
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
22
+ ***********************************************************************
23
+ */
24
+
25
+ #include <stdio.h>
26
+ #include <stdlib.h>
27
+ #include <stdint.h>
28
+
29
+ #include <wiringPi.h>
30
+ #include <piFace.h>
31
+
32
+
33
+ int outputs [4] = { 0,0,0,0 } ;
34
+
35
+ #define PIFACE 200
36
+
37
+ /*
38
+ * light:
39
+ * Light up the given LED - actually lights up a pair
40
+ *********************************************************************************
41
+ */
42
+
43
+ void light (int led, int value)
44
+ {
45
+ led *= 2 ;
46
+ digitalWrite (PIFACE + led + 0, value) ;
47
+ digitalWrite (PIFACE + led + 1, value) ;
48
+ }
49
+
50
+ /*
51
+ * lightAll:
52
+ * All On or Off
53
+ *********************************************************************************
54
+ */
55
+
56
+ void lightAll (int onoff)
57
+ {
58
+ light (0, onoff) ;
59
+ light (1, onoff) ;
60
+ light (2, onoff) ;
61
+ light (3, onoff) ;
62
+ }
63
+
64
+
65
+ /*
66
+ * waitForNoButtons:
67
+ * Wait for all buttons to be released
68
+ *********************************************************************************
69
+ */
70
+
71
+ void waitForNoButtons (void)
72
+ {
73
+ int i, button ;
74
+
75
+ for (;;)
76
+ {
77
+ button = 0 ;
78
+ for (i = 0 ; i < 4 ; ++i)
79
+ button += digitalRead (PIFACE + i) ;
80
+
81
+ if (button == 4)
82
+ break ;
83
+ }
84
+ }
85
+
86
+
87
+ void scanButton (int button)
88
+ {
89
+ if (digitalRead (PIFACE + button) == LOW)
90
+ {
91
+ outputs [button] ^= 1 ;
92
+ digitalWrite (PIFACE + button, outputs [button]) ;
93
+ }
94
+
95
+ while (digitalRead (PIFACE + button) == LOW)
96
+ delay (1) ;
97
+ }
98
+
99
+
100
+ int main (void)
101
+ {
102
+ int i, j ;
103
+ int led, button ;
104
+ unsigned int start, stop ;
105
+
106
+ printf ("Raspberry Pi PiFace Reaction Timer\n") ;
107
+ printf ("==================================\n") ;
108
+
109
+ if (piFaceSetup (PIFACE) == -1)
110
+ exit (1) ;
111
+
112
+ // Enable internal pull-ups
113
+
114
+ for (i = 0 ; i < 8 ; ++i)
115
+ pullUpDnControl (PIFACE + i, PUD_UP) ;
116
+
117
+
118
+ // Main game loop:
119
+ // Put some random LED pairs up for a few seconds, then blank ...
120
+
121
+ for (;;)
122
+ {
123
+ printf ("Press any button to start ... \n") ; fflush (stdout) ;
124
+
125
+ for (;;)
126
+ {
127
+ led = rand () % 4 ;
128
+ light (led, 1) ;
129
+ delay (10) ;
130
+ light (led, 0) ;
131
+
132
+ button = 0 ;
133
+ for (j = 0 ; j < 4 ; ++j)
134
+ button += digitalRead (PIFACE + j) ;
135
+
136
+ if (button != 4)
137
+ break ;
138
+ }
139
+
140
+ waitForNoButtons () ;
141
+
142
+ printf ("Wait for it ... ") ; fflush (stdout) ;
143
+
144
+ led = rand () % 4 ;
145
+ delay (rand () % 500 + 1000) ;
146
+ light (led, 1) ;
147
+
148
+ start = millis () ;
149
+ for (button = -1 ; button == -1 ; )
150
+ {
151
+ for (j = 0 ; j < 4 ; ++j)
152
+ if (digitalRead (PIFACE + j) == 0) // Pushed
153
+ {
154
+ button = j ;
155
+ break ;
156
+ }
157
+ }
158
+ stop = millis () ;
159
+ button = 3 - button ; // Correct for the buttons/LEDs reversed
160
+
161
+ light (led, 0) ;
162
+
163
+ waitForNoButtons () ;
164
+
165
+ light (led, 1) ;
166
+
167
+ if (button == led)
168
+ {
169
+ printf ("You got it in %3d mS\n", stop - start) ;
170
+ }
171
+ else
172
+ {
173
+ printf ("Missed: You pushed %d - LED was %d\n", button, led) ;
174
+ for (;;)
175
+ {
176
+ light (button, 1) ;
177
+ delay (100) ;
178
+ light (button, 0) ;
179
+ delay (100) ;
180
+ i = 0 ;
181
+ for (j = 0 ; j < 4 ; ++j)
182
+ i += digitalRead (PIFACE + j) ;
183
+ if (i != 4)
184
+ break ;
185
+ }
186
+
187
+ waitForNoButtons () ;
188
+ }
189
+ light (led, 0) ;
190
+ delay (4000) ;
191
+ }
192
+
193
+ return 0 ;
194
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * piglow.c:
3
+ * Very simple demonstration of the PiGlow board.
4
+ * This uses the SN3218 directly - soon there will be a new PiGlow
5
+ * devLib device which will handle the PiGlow board on a more easy
6
+ * to use manner...
7
+ *
8
+ * Copyright (c) 2013 Gordon Henderson.
9
+ ***********************************************************************
10
+ * This file is part of wiringPi:
11
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
12
+ *
13
+ * wiringPi is free software: you can redistribute it and/or modify
14
+ * it under the terms of the GNU Lesser General Public License as published by
15
+ * the Free Software Foundation, either version 3 of the License, or
16
+ * (at your option) any later version.
17
+ *
18
+ * wiringPi is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU Lesser General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU Lesser General Public License
24
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
25
+ ***********************************************************************
26
+ */
27
+
28
+ #include <wiringPi.h>
29
+ #include <sn3218.h>
30
+
31
+ #define LED_BASE 533
32
+
33
+ int main (void)
34
+ {
35
+ int i, j ;
36
+
37
+ wiringPiSetupSys () ;
38
+
39
+ sn3218Setup (LED_BASE) ;
40
+
41
+ for (;;)
42
+ {
43
+ for (i = 0 ; i < 256 ; ++i)
44
+ for (j = 0 ; j < 18 ; ++j)
45
+ analogWrite (LED_BASE + j, i) ;
46
+
47
+ for (i = 255 ; i >= 0 ; --i)
48
+ for (j = 0 ; j < 18 ; ++j)
49
+ analogWrite (LED_BASE + j, i) ;
50
+ }
51
+ }