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gs4,B4,Fs4,E5,Eb5,Cs5,B4,E4,Eb4,E4,Fs4,B4,Fs4,Gs4,B4,Fs4,Gs4,B4,B4,Cs5,Eb5,B4,Fs4,Gs4,Fs4, B4,B4,Bb4,B4,Fs4,Gs4,B4,E5,Eb5,E5,Fs5,B4,B4 }; float nyanBeat[]= { si,si,ei,si,si,si,si,si,si,si,si,si,si,ei,ei,si,si,ei,si,si,si,si,si,si,si,si,ei, ei,ei,si,ei,si,si,si,ei,ei,ei,ei,si,si,si,si,si,si,si,si,si,si,si,si,si,si, ei,ei,si,si,si,si,si,si,si,si,si,si,si,si,ei,si,si,si,si,si,si,si,si,ei,ei,ei,ei,ei,si,ei,si,si,si,ei,ei,ei, ei,si,si,si,si,si,si,si,si,si,si,si,si,si,si,ei,ei,si,si,si,si,si,si,si,si,si,si,si,si, ei,si,si,si,si,si,si,si,si,ei,ei,ei,ei,si,si,ei,si,si,si,si,si,si,si,si,si,si, ei,ei,si,si,si,si,si,si,si,si,si,si,si,si,ei,si,si,ei,si,si,si,si,si,si,si,si,si,si, ei,si,si,si,si,si,si,si,si,si,si,ei,ei,ei,si,si,ei,si,si,si,si,si,si,si,si,si,si, ei,ei,si,si,si,si,si,si,si,si,si,si,si,si,ei,si,si,ei,si,si,si,si,si,si,si,si,si,si, ei,si,si,si,si,si,si,si,si,si,si,si,si };//beat array //float song[]; //float beat[]; //float alive_1[]; //float alive_2[]; PwmOut spkr(p26); DigitalIn fire(p14); DigitalIn up(p15); DigitalIn down(p12); DigitalIn left(p13); I2C i2c(p9, p10); const unsigned char addr = 0x42; const unsigned char read = 0x01; int main() { i2c.frequency(1000); // 1kHz while(1) { /* if(up) { // both play master's song unsigned char freq; float note; for(int i = 0; i < sizeof(song) / sizeof(float); i++) { freq = song[i]; note = notes[freq]; i2c.start(); i2c.write(addr); i2c.write(freq); i2c.stop(); spkr.period(1/note); spkr = 0.5f; wait(beat[i]); } i2c.start(); i2c.write(addr); i2c.write(0xFF); // end song code i2c.stop(); spkr = 0; } if(down) { // both play slave's song int prev = -1; freq = 0; i2c.start(); i2c.write(addr | read); while(freq != 0xFF) { freq = i2c.read(addr); if(freq != prev) { note = notes[freq]; spkr.period(1/note); spkr = 0.5f; } prev = freg; } i2c.stop(); spkr = 0; } if(fire) { // secret special sauce unsigned char freq; float note; for(int i = 0; i < sizeof(...); i++) { // play freq = alive_1[i]; note = notes[freq]; spkr.period(1/freq); spkr = 0.5f; // send freq = alive_2[i]; note = notes[freq]; i2c.start(); i2c.write(addr); i2c.write(freq); i2c.stop(); wait(beat[i]); } i2c.start(); i2c.write(addr); i2c.write(0xFF); i2c.stop(); spkr = 0; }*/ if(left) { char freq; float note; for(int i = 0; i < sizeof(nyanNotes) / sizeof(nyanNotes[0]); i++) { freq = nyanNotes[i]; note = notes[freq]; spkr.period( 1 / note); spkr = .5; wait(nyanBeat[i]); } spkr = 0; } } }