![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Framed Laser Harp Implementation with MBed, that allows interface with MIDI synthesizers software.
Fork of LaserHarpProj by
Diff: main.cpp
- Revision:
- 2:21f0ae3bef8a
- Parent:
- 1:2b551cb862fe
--- a/main.cpp Mon Dec 08 22:01:13 2014 +0000 +++ b/main.cpp Tue Dec 09 00:03:45 2014 +0000 @@ -62,21 +62,70 @@ // constructor(i2c object, i2c address of the mpr121) Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); -void fallInterrupt() -{ - int key_code=0; +int fs; +int octave; +void fallInterrupt() { + int fs_code=0; + int oct_code = 0; int i=0; int value=mpr121.read(0x00); value +=mpr121.read(0x01)<<8; + // LED demo mod by J. Hamblen + //pc.printf("MPR value: %x \r\n", value); i=0; - for (i=0; i<12; i++) { - if (((value>>i)&0x01)==1) key_code=i+1; + // puts key number out to LEDs for demo + for (i=0; i<4; i++) { + if (((value>>i)&0x01)==1) fs_code=i+1; + } + switch (fs_code) + { + case 1: + fs = 1; + led1 = 1; + led2 = 0; + break; + case 2: + fs = 0; + led1 = 0; + led2 = 0; + break; + case 3: + fs = -1; + led1 = 0; + led2 = 1; + break; + case 4: + fs = 0; + octave = 0; + led1 = 0; + led2 = 0; + led3 = 0; + led4 = 0; + break; } - led4=key_code & 0x01; - led3=(key_code>>1) & 0x01; - led2=(key_code>>2) & 0x01; - led1=(key_code>>3) & 0x01; - interupt = key_code; + + for (i=4; i<7; i++) { + if (((value>>i)&0x01)==1) oct_code=i; + } + switch (oct_code) + { + case 4: + octave = 12; + led3= 1; + led4 = 0; + break; + case 5: + octave = 0; + led3 = 0; + led4 = 0; + break; + case 6: + octave = -12; + led3 = 0; + led4 = 1; + break; + } + } USBMIDI midi; @@ -125,46 +174,46 @@ if (val1 <0.7 && pval1 > 0.7) { flag1 = 1; } else if (val1 < 0.7 && flag1 ==1) { - midi.write(MIDIMessage::NoteOn(60+interupt)); + midi.write(MIDIMessage::NoteOn(60+fs+octave)); flag1 = 0; } else if (val1 >0.7) { - midi.write(MIDIMessage::NoteOff(60+interupt)); + midi.write(MIDIMessage::NoteOff(60+fs+octave)); flag1 = 0; } if (val2 <0.7 && pval2 > 0.7) { flag2 = 1; } else if (val2 < 0.7 && flag2 ==1) { - midi.write(MIDIMessage::NoteOn(62+interupt)); + midi.write(MIDIMessage::NoteOn(62+fs+octave)); flag2 = 0; } else if (val2 >0.7) { - midi.write(MIDIMessage::NoteOff(62+interupt)); + midi.write(MIDIMessage::NoteOff(62+fs+octave)); flag2 = 0; } if (val3 <0.7 && pval3 > 0.7) { flag3 = 1; } else if (val3 < 0.7 && flag3 ==1) { - midi.write(MIDIMessage::NoteOn(64+interupt)); + midi.write(MIDIMessage::NoteOn(64+fs+octave)); flag3 = 0; } else if (val3 >0.7) { - midi.write(MIDIMessage::NoteOff(64+interupt)); + midi.write(MIDIMessage::NoteOff(64+fs+octave)); flag3 = 0; } if (val4 <0.7 && pval4 > 0.7) { flag4 = 1; } else if (val4 < 0.7 && flag4 ==1) { - midi.write(MIDIMessage::NoteOn(65+interupt)); + midi.write(MIDIMessage::NoteOn(65+fs+octave)); flag4 = 0; } else if (val4 >0.7) { - midi.write(MIDIMessage::NoteOff(65+interupt)); + midi.write(MIDIMessage::NoteOff(65+fs+octave)); flag4 = 0; } if (val5 <0.7 && pval5 > 0.7) { flag5 = 1; } else if (val5 < 0.7 && flag5 ==1) { - midi.write(MIDIMessage::NoteOn(67+interupt)); + midi.write(MIDIMessage::NoteOn(67+fs+octave)); flag5 = 0; } else if (val5 >0.7) { - midi.write(MIDIMessage::NoteOff(67+interupt)); + midi.write(MIDIMessage::NoteOff(67+fs+octave)); flag5 = 0; } }