-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkurodenwa_pls.ino
105 lines (90 loc) · 2.39 KB
/
kurodenwa_pls.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
bool isInit = true;
SoftwareSerial mySoftwareSerial(10, 11);
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
int count = 0;
int old_d5_state = 0;
int old_d8_state = 0;
int old_pls = 0;
unsigned long waiteTime = 0;
void setup()
{
Serial.begin(9600);
mySoftwareSerial.begin(9600);
if (!myDFPlayer.begin(mySoftwareSerial))
{
Serial.println("DFPlayerMiniERR");
isInit = false;
}
pinMode(6, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
}
void loop()
{
if (isInit)
{
if (Serial.available() > 0)
{
String input = ""; // 入力を保存するための文字列バッファ
// 受信した全ての文字をバッファに追加する
while (Serial.available() > 0)
{
char ch = Serial.read();
if (isDigit(ch))
{ // 受け取った文字が数字であるか確認
input += ch;
}
delay(10); // 少し待ってから次の文字を読み取る(データの受信が完了するのを待つため)
}
// バッファが空でない場合に処理
if (input.length() > 0)
{
int num = input.toInt(); // 文字列を整数に変換
myDFPlayer.volume(20); // ボリュームをセット
if (num != 999)
{
myDFPlayer.playMp3Folder(num); // 音声を再生
if (num != -38)
{
delay(10);
}
}
}
}
}
int d6 = digitalRead(6);
int d5 = digitalRead(5);
int d8 = digitalRead(8);
if (d8 == LOW && d5 == HIGH && old_d5_state == LOW)
{
count++;
waiteTime = millis();
}
if (old_d8_state == HIGH && d8 == LOW)
{
count = 0;
}
if ((millis() - waiteTime) > 300)
{
count = 0;
}
if (old_pls > 0 && count == 0)
{
Serial.print(d6);
Serial.print(",");
Serial.println(old_pls);
}
else
{
Serial.print(d6);
Serial.print(",");
Serial.println(0);
}
old_d5_state = d5;
old_d8_state = d8;
old_pls = count;
}