Skip to content

Commit 1bca978

Browse files
authored
Add files via upload
1 parent 2a67e0a commit 1bca978

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

FileParser.ino

+25-17
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,21 @@ void readFromSD() {
5151
}
5252

5353
void readSongParameters() {
54-
for (byte i = 0; i < 2; i++) {
55-
String line = "";
56-
while (textFile.available()) {
57-
char c = textFile.read();
58-
if (c == '\n')
59-
break;
60-
line.concat(c);
61-
}
62-
if (i == 0)
63-
songLines = line.toInt();
64-
else
65-
noteLength = floor((double)1000 * (double)60 / (double)line.toInt());
54+
String line = "";
55+
while (textFile.available()) {;
56+
char c = textFile.read();
57+
if (c == '\n')
58+
break;
59+
line.concat(c);
6660
}
61+
noteLength = floor((double)1000 * (double)60 / (double)line.toInt());
62+
63+
inferLineSize();
64+
inferLineCount();
6765
}
6866

69-
void initializeArray(){
70-
int file_pos = textFile.position();
67+
void inferLineSize(){
68+
unsigned long file_pos = textFile.position();
7169
String token = "";
7270
while (textFile.available()) {
7371
char c = textFile.read();
@@ -80,9 +78,20 @@ void initializeArray(){
8078
else if (c != ' ')
8179
token.concat(c);
8280
}
83-
songLength += 1;
84-
textFile.seek(file_pos);
81+
textFile.seek(file_pos - 1);
82+
}
8583

84+
void inferLineCount(){
85+
unsigned long file_pos = textFile.position();
86+
while (textFile.available()) {
87+
char c = textFile.read();
88+
if (c == '\n')
89+
songLines++;
90+
}
91+
textFile.seek(file_pos+1);
92+
}
93+
94+
void initializeArray(){
8695
score = new byte*[songLines];
8796
for (byte i = 0; i < songLines; i++)
8897
score[i] = new byte[songLength];
@@ -92,7 +101,6 @@ void readSong() {
92101
byte pos = 0;
93102
String token = "";
94103
byte melodicLine = 0;
95-
96104
while (textFile.available()) {
97105
char c = textFile.read();
98106
if (c == '\n') {

PianoRobot.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ short currentNote = 0;
3939

4040
void setup() {
4141

42-
//Serial.begin(115200);
43-
//Serial.println("Start");
42+
Serial.begin(115200);
43+
Serial.println("Start");
4444

4545
readFromSD();
4646

music.txt

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
6
21
120
3-
e4 + + + + + d4 + f4 + + + + e4 d4 c4 d4 e4 e4 + + + d4 + c4 + + c4 c4 + + + e4 + + d4 d4 + + + e4 + + d4 d4 + + e4 c4 d4 + b3 c4 d4 + b3 c4 b3 a3 + e4 d4 + c4 b3 c4 c4 + c4 + + + b3 c4 + c4 + d4 c4 b3 b3 + + + c4 + + +
4-
c4 + + + + + a3 + c4 + + + + g3 f3 e3 _ _ c4 + + + + + a3 + + a3 a3 + + + c4 + + b3 b3 + + + b3 + + + + + b3 + a3 + + + a3 + + + a3 _ _ _ c4 b3 + a3 g3 + g3 + + + + + _ _ _ a3 + _ _ _ g3 + + + g3 + + +
5-
g3 + + + + + f3 + a3 + + + + _ _ _ f3 g3 g3 + + + g3 + e3 + + e3 e3 + + + g3 + + g3 g3 + + + g3 + + + + + g3 + e3 + + + f3 + + + f3 + + + g3 g3 + f3 d3 + e3 + + + + + f3 + + f3 + f3 e3 d3 d3 + + + e3 + + +
6-
c3 + + + c3 + + + f2 + + + f2 + + + d2 + g2 + + + g2 + a2 + + + a2 + + + g2 + + + g2 + + + e2 + + + e2 + + + a2 + + + a2 + + + f2 + + + f2 g2 g2 f2 g2 + + + g2 + + + f2 + + + + + + + g2 + + + e2 + + +
7-
g2 + + + g2 + + + c2 + + + c2 + + + _ _ _ _ _ _ _ _ e2 + + + e2 + + + _ _ _ _ d2 + + + b1 + + + b1 + + + e2 + + + f2 + + + c2 + + + c2 _ d2 c2 d2 + + + _ _ _ _ c2 + + + + + + + d2 + + + c2 + + +
8-
c2 + + + c2 + + + f1 + + + f1 + + + g1 + c2 + + + b1 + a1 + + + a1 + + + c2 + + + g1 + + + e1 + + + e1 + + + a1 + + + c2 + + + f1 + + + f1 c2 g1 f1 g1 + + + c2 + + + f1 + + + + + + g1 g1 + + + g1 + + +
2+
e4 + + + + + d4 + f4 + + + + e4 d4 c4 d4 e4 e4 + + + d4 + c4 + + c4 c4 + + + e4 + + d4 d4 + + + e4 + + d4 c4 d4 + b3 c4 d4 + b3 c4 b3 a3 + e4 d4 + c4 b3 c4 c4 + c4 + + + b3 c4 + c4 + d4 c4 b3 c4 + + +
3+
c4 + + + + + a3 + c4 + + + + g3 f3 e3 _ _ c4 + + + + + a3 + + a3 a3 + + + c4 + + b3 b3 + + + b3 + + + a3 + + + a3 + + _ a3 _ _ _ c4 b3 + a3 g3 + g3 + + + + + _ _ _ a3 + _ _ _ g3 + + +
4+
g3 + + + + + f3 + a3 + + + + _ _ _ f3 g3 g3 + + + g3 + e3 + + e3 e3 + + + g3 + + g3 g3 + + + g3 + + + e3 + + + f3 + + + f3 + + + g3 g3 + f3 d3 + e3 + + + + + f3 + + f3 + f3 e3 d3 e3 + + +
5+
c3 + + + c3 + + + f2 + + + f2 + + + d2 + g2 + + + g2 + a2 + + + a2 + + + g2 + + + g2 + + + e2 + + + a2 + + + a2 + + + f2 + + + f2 g2 g2 f2 g2 + + + g2 + + + f2 + + + + + + + e2 + + +
6+
g2 + + + g2 + + + c2 + + + c2 + + + _ _ _ _ _ _ _ _ e2 + + + e2 + + + _ _ _ _ d2 + + + b1 + + + e2 + + + f2 + + + c2 + + + c2 _ d2 c2 d2 + + + _ _ _ _ c2 + + + + + + + c2 + + +
7+
c2 + + + c2 + + + f1 + + + f1 + + + g1 + c2 + + + b1 + a1 + + + a1 + + + c2 + + + g1 + + + e1 + + + a1 + + + c2 + + + f1 + + + f1 c2 g1 f1 g1 + + + c2 + + + f1 + + + + + + g1 g1 + + +

0 commit comments

Comments
 (0)