-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathSDAnimation.ino
63 lines (49 loc) · 847 Bytes
/
SDAnimation.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
#include "SD.h"
#include "string.h"
File root;
void setup()
{
Serial.begin(9600);
pinMode(10, OUTPUT); // SS pin must be output, change this to 53 on a mega
bool sd_ok = SD.begin(9); // chip select pin
if (!sd_ok)
{
Serial.println("failed.");
return;
}
root = SD.open("/");
}
void sendAnimation(byte *data)
{
Serial.write(0xf2); // batch update supported
for (byte i = 8; i < 72; i++)
{
Serial.write(data[i]);
}
delay(20);
}
void readAnimation(File & file)
{
byte data[72];
while (file.available())
{
file.read(data, 72);
sendAnimation(data);
}
}
void loop(void)
{
File file = root.openNextFile();
if (file)
{
char *p = file.name();
char *p_dot = strchr(p, '.');
if (p_dot != NULL && strcmp(p_dot, ".dat") == 0)
{
readAnimation(file);
}
file.close();
}
else
root.rewindDirectory();
}