-
Notifications
You must be signed in to change notification settings - Fork 0
/
WTV020SD.cpp
81 lines (67 loc) · 1.28 KB
/
WTV020SD.cpp
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
#include <Arduino.h>
#include "WTV020SD.h"
WTV020SD::WTV020SD(int resetPin, int clockPin, int dataPin, int busyPin)
: resetPin(resetPin)
, clockPin(clockPin)
, dataPin(dataPin)
, busyPin(busyPin)
{
init();
}
void WTV020SD::reset()
{
digitalWrite(resetPin, HIGH);
digitalWrite(clockPin, HIGH);
delay(1);
digitalWrite(resetPin, LOW);
delay(10);
digitalWrite(resetPin, HIGH);
delay(600);
}
void WTV020SD::triggerVoice(int fileNumber, bool waitForBusy)
{
sendData(fileNumber);
if (waitForBusy)
{
delay(40);
while (isBusy()) ;
delay(10);
}
}
void WTV020SD::setVolume(int level)
{
sendData(0xFFF0 | level);
}
void WTV020SD::pauseResume()
{
sendData(0xFFFE);
}
void WTV020SD::stop()
{
sendData(0xFFFF);
}
bool WTV020SD::isBusy()
{
return digitalRead(busyPin) == HIGH;
}
void WTV020SD::init()
{
pinMode(resetPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(busyPin, INPUT);
}
void WTV020SD::sendData(unsigned int data)
{
digitalWrite(clockPin, LOW);
delay(4);
for (int i = 8 * sizeof(data) - 1; i >= 0; i--)
{
digitalWrite(dataPin, (data & (1 << i)) ? HIGH : LOW);
digitalWrite(clockPin, LOW);
delayMicroseconds(200);
digitalWrite(clockPin, HIGH);
delayMicroseconds(200);
}
delay(4);
}