質問編集履歴
1
ソースコードに間違いがあったため
test
CHANGED
File without changes
|
test
CHANGED
@@ -183,231 +183,3 @@
|
|
183
183
|
```ここに言語名を入力
|
184
184
|
|
185
185
|
ソースコード
|
186
|
-
|
187
|
-
#include <SD.h>
|
188
|
-
|
189
|
-
#define chipSelect 4
|
190
|
-
|
191
|
-
#define Pina 6 // 2 つのピンに名前を付けておく
|
192
|
-
|
193
|
-
#define Pinb 2
|
194
|
-
|
195
|
-
#define Pinc 5
|
196
|
-
|
197
|
-
const int numa = 10800; // 駆動歯車:2880
|
198
|
-
|
199
|
-
const int numb = 10800; // 被動歯車:3600
|
200
|
-
|
201
|
-
const int numc = 3; //被動歯車Z相
|
202
|
-
|
203
|
-
boolean V1a, V2a, V1b, V2b, V1c, V2c;
|
204
|
-
|
205
|
-
File dataFile;
|
206
|
-
|
207
|
-
static unsigned long startTime;
|
208
|
-
|
209
|
-
int i1,i2,i3;
|
210
|
-
|
211
|
-
void setup(){
|
212
|
-
|
213
|
-
Serial.begin (9600);
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
Serial.print(F("Initializing SD card..."));
|
218
|
-
|
219
|
-
pinMode(10, OUTPUT);
|
220
|
-
|
221
|
-
if (!SD.begin(chipSelect)){
|
222
|
-
|
223
|
-
Serial.println(F("Card failed, or not present"));
|
224
|
-
|
225
|
-
while(1);
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
Serial.println(F("ok."));
|
230
|
-
|
231
|
-
dataFile = SD.open("datalog.txt", FILE_WRITE);
|
232
|
-
|
233
|
-
Serial.println(F("Recored start!"));
|
234
|
-
|
235
|
-
startTime=micros();
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
pinMode(Pina, INPUT);//6(金属)
|
240
|
-
|
241
|
-
pinMode(Pinb, INPUT);//2(プラスチック)
|
242
|
-
|
243
|
-
pinMode(Pinc, INPUT);//Z相
|
244
|
-
|
245
|
-
pinMode(LED_BUILTIN, OUTPUT);
|
246
|
-
|
247
|
-
V1a =0;
|
248
|
-
|
249
|
-
V2a =0;
|
250
|
-
|
251
|
-
V1b =0;
|
252
|
-
|
253
|
-
V2b =0;
|
254
|
-
|
255
|
-
V1c =0;
|
256
|
-
|
257
|
-
V2c =0;
|
258
|
-
|
259
|
-
i1=0;
|
260
|
-
|
261
|
-
i2=0;
|
262
|
-
|
263
|
-
i3=0;
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
void loop(){
|
268
|
-
|
269
|
-
int j,k,l;
|
270
|
-
|
271
|
-
static unsigned long t1[numa+3]={0}, t2[numb+3]={0},t3[numc+3]={0};
|
272
|
-
|
273
|
-
V2a = digitalRead(Pina); // 2 つのピンで読んだ値を V1 と V2 に
|
274
|
-
|
275
|
-
V2b = digitalRead(Pinb);
|
276
|
-
|
277
|
-
V2c = digitalRead(Pinc);
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
if( V1c==0 && V2c>=1 && i3<numc){
|
282
|
-
|
283
|
-
t3[i3] = micros();
|
284
|
-
|
285
|
-
i3++;
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
if(V1a==0 && V2a>=1){
|
292
|
-
|
293
|
-
t1[i1] = micros();
|
294
|
-
|
295
|
-
i1++;
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
if(V1b==0 && V2b>=1){
|
302
|
-
|
303
|
-
t2[i2] = micros();
|
304
|
-
|
305
|
-
i2++;
|
306
|
-
|
307
|
-
}
|
308
|
-
|
309
|
-
if(i2>=numb){
|
310
|
-
|
311
|
-
Serial.print("data record finished");
|
312
|
-
|
313
|
-
if(((micros()-startTime)%1000000000)<50000000){
|
314
|
-
|
315
|
-
for(l=0;l<numc;l++){
|
316
|
-
|
317
|
-
dataFile.println(t3[l]);
|
318
|
-
|
319
|
-
delay(5);
|
320
|
-
|
321
|
-
}
|
322
|
-
|
323
|
-
for(j=0,k=0;j<numa && k<numb ;j++,k++){
|
324
|
-
|
325
|
-
dataFile.print(t1[j]);
|
326
|
-
|
327
|
-
dataFile.print(" ");
|
328
|
-
|
329
|
-
dataFile.println(t2[k]);
|
330
|
-
|
331
|
-
delay(5);
|
332
|
-
|
333
|
-
}
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
for(l=0;l<numc;l++){
|
338
|
-
|
339
|
-
Serial.println(t3[l],4);
|
340
|
-
|
341
|
-
delay(20);
|
342
|
-
|
343
|
-
}
|
344
|
-
|
345
|
-
for(j=0,k=0;j<numa && k<numb ;j++,k++){
|
346
|
-
|
347
|
-
Serial.print(t1[j],4);
|
348
|
-
|
349
|
-
Serial.print(",");
|
350
|
-
|
351
|
-
Serial.println(t2[k],4);
|
352
|
-
|
353
|
-
delay(20);
|
354
|
-
|
355
|
-
}
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
i1=0;
|
360
|
-
|
361
|
-
i2=0;
|
362
|
-
|
363
|
-
i3=0;
|
364
|
-
|
365
|
-
if((micros()-startTime)>40000000){ // 1,000,000micros=1sec 40s
|
366
|
-
|
367
|
-
dataFile.flush();
|
368
|
-
|
369
|
-
dataFile.close();
|
370
|
-
|
371
|
-
Serial.println(F("finished"));
|
372
|
-
|
373
|
-
while(1){
|
374
|
-
|
375
|
-
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
|
376
|
-
|
377
|
-
delay(5000); // wait for a second
|
378
|
-
|
379
|
-
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
|
380
|
-
|
381
|
-
delay(5000); // wait for a second
|
382
|
-
|
383
|
-
}
|
384
|
-
|
385
|
-
}
|
386
|
-
|
387
|
-
}
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
V1a=V2a;
|
392
|
-
|
393
|
-
V1b=V2b;
|
394
|
-
|
395
|
-
V1c=V2c;
|
396
|
-
|
397
|
-
}
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
### 試したこと
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
データ数をそれぞれ54000個のデータを取得したいです
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
### 補足情報(FW/ツールのバージョンなど)
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
ここにより詳細な情報を記載してください。
|