/
eeprom-writesong.ino
168 lines (150 loc) · 7.37 KB
/
eeprom-writesong.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <Wire.h>
#include <avr/pgmspace.h>
#define ext_eeprom 0x50 // address of eeprom chip
/*
*
* // imperial march
const int song[] PROGMEM =
{
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8,
17, 2, 440, 2, 17, 2, 440, 2, 17, 2, 440, 2, 17, 2,
349, 2, 523, 2, 440, 2, 17, 2, 349, 2, 523, 2, 440, 8, 17, 2,
17, 8
};
*/
// random notes
const int song[] PROGMEM =
{218,4,559,3,17,2,459,4,17,2,529,3,17,2,390,4,531,2,17,2,861,4,
17,2,342,3,302,4,893,2,17,2,952,3,779,4,17,2,992,2,285,2,17,2,
657,2,17,2,535,4,17,2,862,2,744,2,417,3,17,2,615,3,17,2,893,2,
17,2,564,3,353,4,17,2,309,4,17,2,610,4,502,2,794,4,651,4,17,2,
682,4,473,2,17,2,566,3,929,2,17,2,689,4,17,2,898,3,794,2,467,2,
17,2,525,4,17,2,997,4,17,2,699,4,17,2,462,3,932,2,317,4,17,2,
563,3,17,2,788,2,223,4,17,2,694,2,424,2,944,3,360,3,547,4,17,2,
462,4,395,4,17,2,698,3,425,4,17,2,382,2,658,3,839,4,17,2,498,4,
475,2,17,2,542,2,297,3,17,2,973,3,17,2,272,3,267,4,17,2,751,2,
17,2,666,3,760,3,428,2,795,2,17,2,378,3,949,2,17,2,444,4,413,3,
17,2,431,2,17,2,556,4,309,3,17,2,940,3,291,2,17,2,492,3,935,4,
17,2,405,3,17,2,272,2,805,4,17,2,240,4,238,4,600,2,626,4,804,4,
933,4,17,2,769,3,17,2,271,3,17,2,991,4,17,2,280,2,328,2,566,4,
371,4,17,2,506,2,945,4,17,2,634,3,824,3,299,4,17,2,585,4,17,2,
852,4,625,2,17,2,667,2,17,2,571,3,17,2,299,2,17,2,275,3,17,2,
716,4,839,4,17,2,959,2,17,2,406,2,718,3,692,3,591,3,17,2,619,4,
17,2,650,4,319,3,17,2,531,2,17,2,957,4,17,2,283,2,17,2,950,3,
617,2,17,2,921,3,17,2,465,3,17,2,660,3,869,3,17,2,381,4,17,2,
555,2,17,2,676,3,697,4,17,2,517,3,17,2,546,3,204,4,509,4,17,2,
258,3,614,2,976,4,343,3,17,2,896,2,688,4,952,4,804,2,627,4,17,2,
968,2,215,4,17,2,860,3,469,4,17,2,887,3,17,2,554,2,480,2,752,3,
887,3,17,2,412,3,494,2,699,2,17,2,242,2,406,3,401,4,17,2,1000,4,
835,2,17,2,783,3,17,2,417,4,17,2,457,3,17,2,345,4,17,2,952,3,
839,2,17,2,343,3,17,2,723,3,17,2,241,3,17,2,273,4,17,2,949,2,
17,2,753,4,17,2,872,2,440,3,219,2,17,2,996,3,975,2,17,2,405,2,
17,2,911,2,17,2,201,3,17,2,336,2,723,3,17,2,661,3,17,2,793,3,
17,2,870,2,852,2,710,3,525,4,17,2,958,2,839,3,17,2,561,4,17,2,
863,3,17,2,907,3,17,2,751,3,17,2,515,4,17,2,355,2,17,2,701,2,
17,2,528,4,722,2,535,2,17,2,374,3,683,3,17,2,881,4,17,2,872,2,
807,4,17,2,220,4,714,3,512,3,828,2,902,2,263,4,17,2,511,4,17,2,
617,3,17,2,629,2,17,2,931,2,17,2,410,3,605,3,17,2,763,2,17,2,
919,2,17,2,257,4,17,2,623,3,17,2,683,2,17,2,738,2,323,3,17,2,
299,3,17,2,479,3,17,2,246,2,345,3,17,2,862,2,842,2,461,4,17,2,
562,2,493,2,17,2,275,4,17,2,915,2,17,2,737,2,17,2,507,3,17,2,
518,2,290,4,404,3,623,4,17,2,245,3,17,2,539,4,17,2,504,4,835,3,
17,2,275,2,17,2,789,4,17,2,327,3,17,2,514,2,621,3,17,2,665,2,
17,2,437,2,17,2,758,3,448,3,922,2,968,4,501,4,17,2,687,4,17,2,
331,3,17,2,715,4,17,2,373,2,17,2,681,4,17,2,362,3,233,4,17,2,
426,2,897,3,17,2,464,2,211,4,17,2,584,2,916,3,501,3,17,2,991,4,
17,2,454,3,644,4,632,4,468,2,954,2,643,2,17,2,661,2,17,2,634,2,
707,3,17,2,858,2,301,3,17,2,254,4,813,2,17,2,730,3,354,3,571,3,
17,2,533,2,17,2,395,3,17,2,876,4,247,2,17,2,655,2,17,2,364,3,
763,2,17,2,498,4,599,4,17,2,962,3,857,2,17,2,903,2,17,2,369,2,
17,2,972,3,468,4,964,3,575,4,17,2,672,3,854,3,872,2,831,2,17,2,
213,2,17,2,951,2,17,2,518,4,447,3,17,2,503,4,17,2,766,3,581,3,
17,2,220,3,804,2,241,2,17,2,316,3,541,2,17,2,603,4,17,2,832,3,
978,3,440,3,816,4,770,2,732,4,311,2,17,2,839,4,17,2,821,2,17,2,
916,3,364,2,392,4,814,4,731,4,17,2,202,3,724,4,572,3,704,2,256,3,
814,4,452,3,912,4,766,3,732,4,786,2,885,4,17,2,931,2,17,2,687,2,
17,2,221,2,17,2,592,2,983,4,17,2,448,3,441,4,17,2,912,2,882,2,
968,4,759,2,17,2,909,3,17,2,752,2,751,2,17,2,933,4,17,2,563,4,
17,2,443,3,17,2,820,2,947,3,17,2,453,4,17,2,335,3,17,2,652,2,
755,3,17,2,511,4,17,2,467,2,17,2,459,3,17,2,879,2,17,2,228,3,
509,2,17,2,830,3,897,3,17,2,468,2,739,3,17,2,326,2,533,4,17,2,
559,4,17,2,670,4,354,4,566,3,247,3,17,2,206,2,977,3,17,2,646,2,
442,2,809,3,17,2,961,2,17,2,447,3,17,2,358,2,277,4,17,2,290,4,894,3};
int sizeofarray = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
Serial.println("Writing song to eeprom, connect now...");
Serial.println("");
sizeofarray = (sizeof(song) / sizeof(song[0]));
delay(1000);
writeonce();
}
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(data);
Wire.endTransmission();
Serial.print("Writing ");
Serial.print(data);
Serial.print(" to ");
Serial.println(eeaddress);
delay(10);
}
void writeonce() {
int eepromaddress;
for (int thisone = 0; thisone < sizeofarray; thisone++) {
int thisnumber = pgm_read_word_near(&song[thisone]);
eepromaddress = thisone * 2;
writeEEPROM(ext_eeprom, eepromaddress, highByte(thisnumber));
writeEEPROM(ext_eeprom, eepromaddress + 1, lowByte(thisnumber));
}
}
void loop() {
}