Showing
34 changed files
with
200 additions
and
0 deletions
lab2-2-1
→
assignment/lab2-2-1
100755 → 100644
No preview for this file type
File moved
lab2-2-2
→
assignment/lab2-2-2
100755 → 100644
No preview for this file type
File moved
lab2-2-3
→
assignment/lab2-2-3
100755 → 100644
No preview for this file type
File moved
lab2-2-4
→
assignment/lab2-2-4
100755 → 100644
No preview for this file type
File moved
lab2-3-1
→
assignment/lab2-3-1
100755 → 100644
No preview for this file type
File moved
lab2-3-2
→
assignment/lab2-3-2
100755 → 100644
No preview for this file type
assignment/lab2-3-2(new).c
0 → 100644
1 | +// Wiring Pi Library | ||
2 | +#include <wiringPi.h> | ||
3 | +const int LedRed[8] = { 4, 17, 18, 27, 22, 23, 24, 25 }; | ||
4 | +const int Keypad[5] = { 6, 12, 13, 16, 19 }; | ||
5 | +int KeypadRead() | ||
6 | +{ | ||
7 | + int i, keypadnum = -1; | ||
8 | + for (i = 0; i < 2; i++) { | ||
9 | + if (!digitalRead(Keypad[i])) { | ||
10 | + keypadnum = i; break; | ||
11 | + } | ||
12 | + } | ||
13 | + return keypadnum; | ||
14 | +} | ||
15 | +void LedControl(int num) | ||
16 | +{ | ||
17 | + int i; | ||
18 | + for (i = 0; i < 8; i++) { | ||
19 | + if (i == num) | ||
20 | + digitalWrite(LedRed[i], HIGH); | ||
21 | + else | ||
22 | + digitalWrite(LedRed[i], LOW); | ||
23 | + } | ||
24 | +} | ||
25 | +void stop() { | ||
26 | + LedControl(-1); | ||
27 | +} | ||
28 | +int main(void) | ||
29 | +{ | ||
30 | + int i, keypadnum = -1; | ||
31 | + if (wiringPiSetupGpio() == -1) | ||
32 | + return 1; | ||
33 | + for (i = 0; i < 8; i++) { | ||
34 | + pinMode(LedRed[i], OUTPUT); | ||
35 | + digitalWrite(LedRed[i], LOW); | ||
36 | + } | ||
37 | + for (i = 0; i < 2; i++) | ||
38 | + pinMode(Keypad[i], INPUT); | ||
39 | + if (wiringPiISR(Keypad[2], INT_EDGE_FALLING, &stop) < 0) { | ||
40 | + return 1; | ||
41 | + } | ||
42 | + | ||
43 | + while (1) { | ||
44 | + keypadnum = KeypadRead(); | ||
45 | + if (keypadnum == 0) { | ||
46 | + while (1) { | ||
47 | + for (i = 0; i < 8; i++) { | ||
48 | + LedControl(i); | ||
49 | + delay(500); | ||
50 | + } | ||
51 | + digitalWrite(LedRed[i - 1], LOW); | ||
52 | + } | ||
53 | + } | ||
54 | + else if (keypadnum == 1) { | ||
55 | + while (1) { | ||
56 | + for (i = 7; i >= 0; i--) { | ||
57 | + LedControl(i); | ||
58 | + delay(500); | ||
59 | + } | ||
60 | + digitalWrite(LedRed[i + 1], LOW); | ||
61 | + } | ||
62 | + } | ||
63 | + if (keypadnum == 3) { | ||
64 | + for (i = 0; i < 8; i++) { | ||
65 | + LedControl(i); | ||
66 | + delay(500); | ||
67 | + } | ||
68 | + digitalWrite(LedRed[i - 1], LOW); | ||
69 | + } | ||
70 | + else if (keypadnum == 4) { | ||
71 | + for (i = 7; i >= 0; i--) { | ||
72 | + LedControl(i); | ||
73 | + delay(500); | ||
74 | + } | ||
75 | + digitalWrite(LedRed[i + 1], LOW); | ||
76 | + } | ||
77 | + } | ||
78 | + return 0; | ||
79 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
File moved
lab2-4-1
→
assignment/lab2-4-1
100755 → 100644
No preview for this file type
File moved
lab2-4-2
→
assignment/lab2-4-2
100755 → 100644
No preview for this file type
File moved
lab2-5-1
→
assignment/lab2-5-1
100755 → 100644
No preview for this file type
File moved
lab2-5-2
→
assignment/lab2-5-2
100755 → 100644
No preview for this file type
File moved
example/lab2-2_1.c
0 → 100644
1 | +// Wiring Pi Library 헤더파일 선언 | ||
2 | +#include <wiringPi.h> | ||
3 | +// LED ON/OFF 정의 | ||
4 | +#define LED_ON 1 | ||
5 | +#define LED_OFF 0 | ||
6 | +// 라즈베리파이 및 LED 핀 정의 | ||
7 | +const int Led[16] = { | ||
8 | + 4, 17, 18, 27, 22, 23, 24, 25, | ||
9 | + 6, 12, 13, 16, 19, 20, 26, 21 | ||
10 | +}; | ||
11 | +int main(void){ | ||
12 | + int i; // for문 변수 | ||
13 | + if(wiringPiSetupGpio() == -1) // GPIO 초기화 | ||
14 | + return 1; | ||
15 | + for(i=0; i<16; i++){ | ||
16 | + pinMode(Led[i], OUTPUT); // LED 핀 출력모드 설정 | ||
17 | + digitalWrite(Led[i], LED_OFF); // LED 전체 OFF | ||
18 | + } | ||
19 | + while(1){ | ||
20 | + digitalWrite(Led[0], LED_ON); // LED 1 ON | ||
21 | + delay(500); // 500ms 지연 | ||
22 | + digitalWrite(Led[0], LED_OFF); // LED 1 OFF | ||
23 | + delay(500); // 500ms 지연 | ||
24 | + } | ||
25 | + return 0; | ||
26 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
example/lab2-2_2.c
0 → 100644
1 | +#include <wiringPi.h>// Wiring Pi Library 헤더파일 선언 | ||
2 | +#define LED_OFF 0 // LED OFF 정의 | ||
3 | +#define LED_ON 1 // LED ON 정의 | ||
4 | +#define LED_RED 2 // LED RED 정의 | ||
5 | +#define LED_GREEN 3 // LED GREEN 정의 | ||
6 | +// 라즈베리파이 및 LED RED / GREEN 핀 정의 | ||
7 | +const int LedRed [8] = { 4, 17, 18, 27, 22, 23, 24, 25 }; | ||
8 | +const int LedGreen [8] = { 6, 12, 13, 16, 19, 20, 26, 21 }; | ||
9 | +void LEDControl(int color) { | ||
10 | + int i; | ||
11 | + if(color == LED_RED) { | ||
12 | + for(i=0; i<8; i++) { | ||
13 | + digitalWrite(LedRed[i], LED_ON); | ||
14 | + digitalWrite(LedGreen[i], LED_OFF); | ||
15 | + } | ||
16 | + } | ||
17 | + else if(color == LED_GREEN) { | ||
18 | + for(i=0; i<8; i++) { | ||
19 | + digitalWrite(LedRed[i], LED_OFF); | ||
20 | + digitalWrite(LedGreen[i], LED_ON); | ||
21 | + } | ||
22 | + } | ||
23 | +} | ||
24 | +int main(void){ | ||
25 | + int i; | ||
26 | + if(wiringPiSetupGpio() == -1) | ||
27 | + return 1; | ||
28 | + for(i=0; i<8; i++){ | ||
29 | + pinMode(LedRed[i], OUTPUT); | ||
30 | + pinMode(LedGreen[i], OUTPUT); | ||
31 | + digitalWrite(LedRed[i], LED_OFF); | ||
32 | + digitalWrite(LedGreen[i], LED_OFF); | ||
33 | + } | ||
34 | + while(1){ | ||
35 | + LEDControl(LED_RED); | ||
36 | + delay(500); | ||
37 | + LEDControl(LED_GREEN); | ||
38 | + delay(500); | ||
39 | + } | ||
40 | + return 0; | ||
41 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
lab2-2_3
→
example/lab2-2_3
100755 → 100644
No preview for this file type
lab2-2_3.c
→
example/lab2-2_3.c
100755 → 100644
File mode changed
lab2-3_1
→
example/lab2-3_1
100755 → 100644
No preview for this file type
File moved
example/lab2-3_2.c
0 → 100644
1 | +// Wiring Pi Library | ||
2 | +#include <wiringPi.h> | ||
3 | +const int LedRed[8] = { 4, 17, 18, 27, 22, 23, 24, 25 }; | ||
4 | +const int Keypad[2] = { 16, 19 }; | ||
5 | +int KeypadRead() | ||
6 | +{ | ||
7 | + int i, keypadnum = -1; | ||
8 | + for (i = 0; i < 2; i++) { | ||
9 | + if (!digitalRead(Keypad[i])) { | ||
10 | + keypadnum = i; break; | ||
11 | + } | ||
12 | + } | ||
13 | + return keypadnum; | ||
14 | +} | ||
15 | +void LedControl(int num) | ||
16 | +{ | ||
17 | + int i; | ||
18 | + for (i = 0; i < 8; i++) { | ||
19 | + if (i == num) | ||
20 | + digitalWrite(LedRed[i], HIGH); | ||
21 | + else | ||
22 | + digitalWrite(LedRed[i], LOW); | ||
23 | + } | ||
24 | +} | ||
25 | +int main(void) | ||
26 | +{ | ||
27 | + int i, keypadnum = -1; | ||
28 | + if (wiringPiSetupGpio() == -1) | ||
29 | + return 1; | ||
30 | + for (i = 0; i < 8; i++) { | ||
31 | + pinMode(LedRed[i], OUTPUT); | ||
32 | + digitalWrite(LedRed[i], LOW); | ||
33 | + } | ||
34 | + for (i = 0; i < 2; i++) | ||
35 | + pinMode(Keypad[i], INPUT); | ||
36 | + while (1) { | ||
37 | + keypadnum = KeypadRead(); | ||
38 | + if (keypadnum == 0) { | ||
39 | + for (i = 0; i < 8; i++) { | ||
40 | + LedControl(i); | ||
41 | + delay(500); | ||
42 | + } | ||
43 | + digitalWrite(LedRed[i - 1], LOW); | ||
44 | + } | ||
45 | + else if (keypadnum == 1) { | ||
46 | + for (i = 7; i >= 0; i--) { | ||
47 | + LedControl(i); | ||
48 | + delay(500); | ||
49 | + } | ||
50 | + digitalWrite(LedRed[i + 1], LOW); | ||
51 | + } | ||
52 | + } | ||
53 | + return 0; | ||
54 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
lab2-4_1
→
example/lab2-4_1
100755 → 100644
No preview for this file type
File moved
lab2-4_2
→
example/lab2-4_2
100755 → 100644
No preview for this file type
File moved
lab2-5_1
→
example/lab2-5_1
100755 → 100644
No preview for this file type
File moved
-
Please register or login to post a comment