質問編集履歴
2
行番号を削除しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,184 +18,180 @@
|
|
18
18
|
|
19
19
|
```
|
20
20
|
|
21
|
-
|
21
|
+
#include<stdio.h>
|
22
22
|
|
23
|
-
|
23
|
+
#include<string.h>
|
24
24
|
|
25
|
-
|
25
|
+
#include<wiringPi.h>
|
26
26
|
|
27
|
-
|
27
|
+
#include<signal.h>
|
28
28
|
|
29
|
-
|
29
|
+
#define GPIO_LED 21
|
30
30
|
|
31
|
-
|
31
|
+
#define GPIO_TCT 20
|
32
32
|
|
33
|
-
|
33
|
+
#define GPIO_BUZ 5
|
34
34
|
|
35
|
-
8
|
36
35
|
|
37
|
-
9 void motion_on(int flag2);
|
38
36
|
|
39
|
-
|
37
|
+
void motion_on(int flag2);
|
40
38
|
|
41
|
-
|
39
|
+
void motion_off(void);
|
42
40
|
|
43
|
-
|
41
|
+
void Signal (int sig_name);
|
44
42
|
|
45
|
-
|
43
|
+
void SetSignal(int sig_name);
|
46
44
|
|
47
|
-
|
45
|
+
void tct_callbak(void);
|
48
46
|
|
49
|
-
|
47
|
+
volatile sig_atomic_t flag = 0;
|
50
48
|
|
51
|
-
|
49
|
+
|
52
50
|
|
53
|
-
|
51
|
+
int main(void){
|
54
52
|
|
55
|
-
|
53
|
+
|
56
54
|
|
57
|
-
|
55
|
+
if(wiringPiSetupGpio()==-1){
|
58
56
|
|
59
|
-
|
57
|
+
return 1;
|
60
58
|
|
61
|
-
|
59
|
+
}
|
62
60
|
|
63
|
-
|
61
|
+
pinMode(GPIO_LED,OUTPUT);
|
64
62
|
|
65
|
-
|
63
|
+
pinMode(GPIO_TCT,INPUT);
|
66
64
|
|
67
|
-
|
65
|
+
pinMode(GPIO_BUZ,OUTPUT);
|
68
66
|
|
69
|
-
|
67
|
+
pullUpDnControl(GPIO_TCT,PUD_DOWN);
|
70
68
|
|
71
|
-
|
69
|
+
pullUpDnControl(GPIO_LED,PUD_DOWN);
|
72
70
|
|
73
|
-
|
71
|
+
pullUpDnControl(GPIO_BUZ,PUD_DOWN);
|
74
72
|
|
75
|
-
|
73
|
+
signal(SIGINT,Signal);
|
76
74
|
|
77
|
-
|
75
|
+
wiringPiISR(GPIO_TCT,INT_EDGE_BOTH,tct_callbak);
|
78
76
|
|
79
|
-
|
77
|
+
|
80
78
|
|
81
|
-
|
79
|
+
while(flag==0){
|
82
80
|
|
83
|
-
|
81
|
+
};
|
84
82
|
|
85
|
-
|
83
|
+
return 0;
|
86
84
|
|
87
|
-
|
85
|
+
}
|
88
86
|
|
89
|
-
|
87
|
+
|
90
88
|
|
91
|
-
|
89
|
+
void tct_callbak(void){
|
92
90
|
|
93
|
-
|
91
|
+
if(digitalRead(GPIO_TCT)==HIGH){
|
94
92
|
|
95
|
-
|
93
|
+
motion_on(1);
|
96
94
|
|
97
|
-
|
95
|
+
}else if(digitalRead(GPIO_TCT)==LOW){
|
98
96
|
|
99
|
-
|
97
|
+
motion_off() ;
|
100
98
|
|
101
|
-
|
99
|
+
}
|
102
100
|
|
103
|
-
|
101
|
+
}
|
104
102
|
|
105
|
-
|
103
|
+
|
106
104
|
|
107
|
-
|
105
|
+
void motion_on(int flag2){
|
108
106
|
|
109
|
-
|
107
|
+
|
110
108
|
|
111
|
-
|
109
|
+
digitalWrite(GPIO_BUZ,HIGH);
|
112
110
|
|
113
|
-
|
111
|
+
|
114
112
|
|
115
|
-
|
113
|
+
for(int i=0; i<10;i++){
|
116
114
|
|
117
|
-
|
115
|
+
digitalWrite(GPIO_LED,HIGH);
|
118
116
|
|
119
|
-
|
117
|
+
delay(500);
|
120
118
|
|
121
|
-
|
119
|
+
digitalWrite(GPIO_LED,LOW);
|
122
120
|
|
123
|
-
|
121
|
+
delay(500);
|
124
122
|
|
125
|
-
|
123
|
+
}
|
126
124
|
|
127
|
-
|
125
|
+
|
128
126
|
|
129
|
-
|
127
|
+
flag2=1;
|
130
128
|
|
131
|
-
|
129
|
+
while(flag2==1){
|
132
130
|
|
133
|
-
|
131
|
+
digitalWrite(GPIO_LED,HIGH);
|
134
132
|
|
135
|
-
|
133
|
+
digitalWrite(GPIO_BUZ,HIGH);
|
136
134
|
|
137
|
-
|
135
|
+
}
|
138
136
|
|
139
|
-
|
137
|
+
}
|
140
138
|
|
141
|
-
|
139
|
+
|
142
140
|
|
143
|
-
|
141
|
+
void motion_off(void){
|
144
142
|
|
145
|
-
|
143
|
+
printf("OFFのよびだし");
|
146
144
|
|
147
|
-
|
145
|
+
digitalWrite(GPIO_BUZ,LOW);
|
148
146
|
|
149
|
-
|
147
|
+
digitalWrite(GPIO_LED,LOW);
|
150
148
|
|
151
|
-
|
149
|
+
motion_on(0);
|
152
150
|
|
153
|
-
|
151
|
+
}
|
154
152
|
|
155
|
-
|
153
|
+
|
156
154
|
|
157
|
-
|
155
|
+
void SetSignal(int sig_name){
|
158
156
|
|
159
|
-
|
157
|
+
|
160
158
|
|
161
|
-
|
159
|
+
f(signal(sig_name , Signal)==SIG_ERR){
|
162
160
|
|
163
|
-
|
161
|
+
printf("シグナル設定が出来ませんでした");
|
164
162
|
|
165
|
-
|
163
|
+
}
|
166
164
|
|
167
|
-
|
165
|
+
}
|
168
166
|
|
169
|
-
|
167
|
+
|
170
168
|
|
171
|
-
|
169
|
+
void Signal (int sig_name){
|
172
170
|
|
173
|
-
|
171
|
+
|
174
172
|
|
175
|
-
|
173
|
+
char str[3];
|
176
174
|
|
177
|
-
|
175
|
+
char str2[]="YES";
|
178
176
|
|
179
|
-
|
177
|
+
printf("システムを終了しますか。YES/NO\n");
|
180
178
|
|
181
|
-
|
179
|
+
scanf("%s",str);
|
182
180
|
|
183
|
-
|
181
|
+
|
184
182
|
|
185
|
-
|
183
|
+
if(strcmp (str,str2)==0){
|
186
184
|
|
187
|
-
|
185
|
+
flag=1;
|
188
186
|
|
189
|
-
|
187
|
+
}else{
|
190
188
|
|
191
|
-
|
189
|
+
flag=0;
|
192
190
|
|
193
|
-
|
191
|
+
}
|
194
192
|
|
195
|
-
|
193
|
+
|
196
194
|
|
197
|
-
89
|
198
|
-
|
199
|
-
|
195
|
+
}
|
200
196
|
|
201
197
|
```
|
1
<code>の「```」中にコードを入力しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
また、シグナルハンドラを呼び出した際にもLEDとブザーが反応したままなので、消したいです。
|
18
18
|
|
19
|
-
|
19
|
+
```
|
20
20
|
|
21
21
|
1 #include<stdio.h>
|
22
22
|
|
@@ -197,3 +197,5 @@
|
|
197
197
|
89
|
198
198
|
|
199
199
|
90 }
|
200
|
+
|
201
|
+
```
|