Sie sind auf Seite 1von 5

Berryclip 6 LED Board Testing in C http://www.raspberrypi-spy.co.

uk/2013/04/berryclip-6-led-board-testing-in-c/

1 #include <wiringPi.h>
2 #include <stdlib.h>
3
4 int leds[6] = { 7, 0, 3, 12, 13, 14 };
5 int BUZZER = 10;
6 int BUTTON = 11;
7 void all_leds_off();
8 void init_pins();
9
10 int main (void) {
11 //Check we have wiringPi
12 if (wiringPiSetup () == -1 ) exit (1);
13 init_pins();
14 all_leds_off();
15 for (;;) {

1 of 5 5/5/17, 9:08 PM
Berryclip 6 LED Board Testing in C http://www.raspberrypi-spy.co.uk/2013/04/berryclip-6-led-board-testing-in-c/

16 if (digitalRead (BUTTON) == 1 ) {
17 for (int i = 0; i < 6; i++) {
18 digitalWrite (BUZZER,1);
19 digitalWrite (leds[i],1);
20 delay (50);
21 digitalWrite (BUZZER,0);
22 delay (450);
23 }
24 delay (1000);
25 all_leds_off();
26 }
27 delay(50);
28 }
29 exit(0);
30 }
31
32 void init_pins() {
33 //set leds as outputs...
34 for (int i = 0; i < 6; i++) {
35 pinMode(leds[i], OUTPUT);
36 }
37 // set buzzer as output...
38 pinMode(BUZZER, OUTPUT);
39
40 // set button as an input...
41 pinMode(BUTTON, INPUT);
42 }
43
44 void all_leds_off() {
45 for (int i = 0; i < 6; i++) {
46 digitalWrite (leds[i],0);
47 }
48 }

1 DEBUG = -O3
2 CC = gcc
3 INCLUDE = -I/usr/local/include
4 CFLAGS = $(DEBUG) -Wall -std=c99 $(INCLUDE) -Winline -pipe
5
6 LDFLAGS = -L/usr/local/lib
7 LIBS = -lwiringPi
8
9 OBJ = test1.o
10
11 BINS = test1
12
13 test1: test1.o
14 @echo [link]$(CC) -o $@ test1.o $(LDFLAGS) $(LIBS)
15
16 .c.o:
17 @echo [CC] $<
18 @$(CC) -c $(CFLAGS) $< -o $@
19

2 of 5 5/5/17, 9:08 PM
Berryclip 6 LED Board Testing in C http://www.raspberrypi-spy.co.uk/2013/04/berryclip-6-led-board-testing-in-c/

20 clean:
21 rm -f $(OBJ) *~ test1

make

sudo ./test1

3 of 5 5/5/17, 9:08 PM
Berryclip 6 LED Board Testing in C http://www.raspberrypi-spy.co.uk/2013/04/berryclip-6-led-board-testing-in-c/

4 of 5 5/5/17, 9:08 PM
Berryclip 6 LED Board Testing in C http://www.raspberrypi-spy.co.uk/2013/04/berryclip-6-led-board-testing-in-c/

Select Month

5 of 5 5/5/17, 9:08 PM

Das könnte Ihnen auch gefallen