slave

Dependencies:   mbed music2

Committer:
TylerMuch
Date:
Wed Feb 19 01:02:05 2014 +0000
Revision:
0:acf1f01685d5
done

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TylerMuch 0:acf1f01685d5 1 #include "mbed.h"
TylerMuch 0:acf1f01685d5 2 #include "music.h"
TylerMuch 0:acf1f01685d5 3
TylerMuch 0:acf1f01685d5 4 float song[];
TylerMuch 0:acf1f01685d5 5 float beat[];
TylerMuch 0:acf1f01685d5 6
TylerMuch 0:acf1f01685d5 7 I2CSlace i2c(p9, p10);
TylerMuch 0:acf1f01685d5 8 PwmOut spkr(p26);
TylerMuch 0:acf1f01685d5 9
TylerMuch 0:acf1f01685d5 10
TylerMuch 0:acf1f01685d5 11
TylerMuch 0:acf1f01685d5 12 int main() {
TylerMuch 0:acf1f01685d5 13 i2c.address(0x42);
TylerMuch 0:acf1f01685d5 14 while(1)
TylerMuch 0:acf1f01685d5 15 {
TylerMuch 0:acf1f01685d5 16 int recv = i2c.receive();
TylerMuch 0:acf1f01685d5 17 unsigned char note = i2c.read();
TylerMuch 0:acf1f01685d5 18 switch(recv) {
TylerMuch 0:acf1f01685d5 19 case I2CSlave::WriteAddressed:
TylerMuch 0:acf1f01685d5 20 // receiving song from master
TylerMuch 0:acf1f01685d5 21 if(note == 0xFF) spkr = 0;
TylerMuch 0:acf1f01685d5 22 spkr.period(1/notes[note]);
TylerMuch 0:acf1f01685d5 23 spkr = 0.5f;
TylerMuch 0:acf1f01685d5 24 break;
TylerMuch 0:acf1f01685d5 25 case I2CSlave::ReadAddressed:
TylerMuch 0:acf1f01685d5 26 // sending song to master
TylerMuch 0:acf1f01685d5 27 for(int i = 0; i < sizeof(...); i++)
TylerMuch 0:acf1f01685d5 28 {
TylerMuch 0:acf1f01685d5 29 note = song[i];
TylerMuch 0:acf1f01685d5 30 i2c.write(note);
TylerMuch 0:acf1f01685d5 31 spkr = 0.5f;
TylerMuch 0:acf1f01685d5 32 spkr.period(1/notes[note]);
TylerMuch 0:acf1f01685d5 33 wait(beat[i]);
TylerMuch 0:acf1f01685d5 34 }
TylerMuch 0:acf1f01685d5 35 spkr = 0;
TylerMuch 0:acf1f01685d5 36 break;
TylerMuch 0:acf1f01685d5 37 }
TylerMuch 0:acf1f01685d5 38 }
TylerMuch 0:acf1f01685d5 39 }