Components and supplies
LDR, 5 Mohm
Resistor 10k ohm
Arduino UNO
Laser Diode, 655 nm
Tools and machines
Mircroscope slides
Apps and platforms
GarageBand
Hairless MIDI
MIDI loop
Project description
Code
Programming and algorithm
arduino
1#include <MIDI.h> // this code uses MIDI arduino library (previous codes used) 2// Created and binds the MIDI interface to the default hardware Serial port 3MIDI_CREATE_DEFAULT_INSTANCE(); 4// Piano Guitar sample 12/24/16 5// User settable variables 6//***************************************************************************************************** 7int strings=3;//number of strings 8int frets=2;//number of frets 9int TOTAL=strings*(frets+1);// number of LDRs 10int PlayNote[9]; 11int Onetime[ ]={0,0,0};// to make sure a note doesn’t play twice. 12int string=0; 13int DELAY=200; // This puts time difference until next MIDI is sent 14//****************************************************************************************************** 15//Internal Use Variables 16//****************************************************************************************************** 17int pin; 18int note0=10; 19int note1=10; 20int note2=10; 21int NOWnote=0; 22int hit; 23//boolean error=false; 24//****************************************************************************************************** 25//Setup 26//****************************************************************************************************** 27void setup() 28{ 29Serial.begin(115200); 30} 31//****************************************************************************************************** 32//Main Program 33//****************************************************************************************************** 34void loop() 35{ 36// takes sensors input 37 for (pin=0; pin < strings ; pin++) // takes inputs from pin responsible for the plucking 38{ // lowest note assigned to first pin 39 hit = digitalRead(pin); // read the input pin 40 PlayNote[pin]=hit;// stores the results from the pins inputs 41} 42 for (pin=strings; pin < TOTAL ; pin++) // takes inputs from pin responsible for the plucking 43{ // lowest note assigned to first pin 44 hit = digitalRead(pin); // read the input pin 45 PlayNote[pin]=hit; 46} 47//****************************************************************************************************** 48//Play music 49//****************************************************************************************************** 50 51 if(note0!=-2&¬e1!=-2&¬e2!=-2)// check if there is an error or not. 52 { 53 if (PlayNote[0]==1&&Onetime[0]!=1) // pluck string 0 // makes sure not to play two notes 54 { 55 NOWnote=note0; 56 Onetime[0]=1; // played and waits untill ur the finger is off 57 } 58 else if (PlayNote[1]==1&&Onetime[1]!=1) // pluck string 1 59 { 60 NOWnote=note1; 61 Onetime[1]=1; // played and waits untill ur the finger is off 62 } 63 else if (PlayNote[2]==1&&Onetime[2]!=1) // pluck string 2 64 { 65 NOWnote=note2; 66 Onetime[2]=1; // played and waits untill ur the finger is off 67 } 68 MIDI.sendNoteOn(NOWnote,127,0); 69 delay(DELAY); //play note: meaning pluck 70 } 71 else // find the right note 72 { 73 note0=find_note(PlayNote,0); 74 note1=find_note(PlayNote,1); 75 note2=find_note(PlayNote,2); 76 } 77 78 for(int i=0;i<strings;i++)// resets the logic test 79 { 80 if (PlayNote[i]==0) 81 { 82 Onetime[i]=0; 83 } 84 } 85} 86//****************************************************************************************************** 87//Find MIDI note 88//****************************************************************************************************** 89int find_note(int PlayNote[9] ,int string ) 90{ 91int AllNote[3][3] ={ {50,68,69} , {62,63,64} , {66,67,68} }; // order is importent 92int note=-2; 93int j=0; 94int notes[ ]={50,68,69}; 95int Play[]={0,0}; 96//loading the notes 97for (int i=0;i<4;i++) 98{ 99notes[i]=AllNote[string][i]; 100} 101//take the frets input 102for (int i=2*string+3;i<2*string+5;i++) //loading the inputs 103{ 104Play[j]=PlayNote[i]; 105j++; 106} 107//logic 108 if (Play[1]==0 && Play[2]==0) // no fretting 109 { 110 note=notes[0]; //open string 111 } 112 else if (Play[0]==1 && Play[1]==1) // fret 1 which blocks two LDRs in a row 113 { 114 note=notes[1]; //first fret is pressed 115 } 116 else if (Play[0]==0 && Play[1]==1 ) // fret 2 which only blocks last LDR in a row 117 { 118 note=notes[2]; //second fret is pressed 119 } 120 else 121 { 122 // error=true; 123 note=-2; 124 } 125 return note; 126} 127[/code]
Programming and algorithm
arduino
1#include <MIDI.h> // this code uses MIDI arduino library (previous codes used) 2// Created and binds the MIDI interface to the default hardware Serial port 3MIDI_CREATE_DEFAULT_INSTANCE(); 4// Piano Guitar sample 12/24/16 5// User settable variables 6//***************************************************************************************************** 7int strings=3;//number of strings 8int frets=2;//number of frets 9int TOTAL=strings*(frets+1);// number of LDRs 10int PlayNote[9]; 11int Onetime[ ]={0,0,0};// to make sure a note doesn’t play twice. 12int string=0; 13int DELAY=200; // This puts time difference until next MIDI is sent 14//****************************************************************************************************** 15//Internal Use Variables 16//****************************************************************************************************** 17int pin; 18int note0=10; 19int note1=10; 20int note2=10; 21int NOWnote=0; 22int hit; 23//boolean error=false; 24//****************************************************************************************************** 25//Setup 26//****************************************************************************************************** 27void setup() 28{ 29Serial.begin(115200); 30} 31//****************************************************************************************************** 32//Main Program 33//****************************************************************************************************** 34void loop() 35{ 36// takes sensors input 37 for (pin=0; pin < strings ; pin++) // takes inputs from pin responsible for the plucking 38{ // lowest note assigned to first pin 39 hit = digitalRead(pin); // read the input pin 40 PlayNote[pin]=hit;// stores the results from the pins inputs 41} 42 for (pin=strings; pin < TOTAL ; pin++) // takes inputs from pin responsible for the plucking 43{ // lowest note assigned to first pin 44 hit = digitalRead(pin); // read the input pin 45 PlayNote[pin]=hit; 46} 47//****************************************************************************************************** 48//Play music 49//****************************************************************************************************** 50 51 if(note0!=-2&¬e1!=-2&¬e2!=-2)// check if there is an error or not. 52 { 53 if (PlayNote[0]==1&&Onetime[0]!=1) // pluck string 0 // makes sure not to play two notes 54 { 55 NOWnote=note0; 56 Onetime[0]=1; // played and waits untill ur the finger is off 57 } 58 else if (PlayNote[1]==1&&Onetime[1]!=1) // pluck string 1 59 { 60 NOWnote=note1; 61 Onetime[1]=1; // played and waits untill ur the finger is off 62 } 63 else if (PlayNote[2]==1&&Onetime[2]!=1) // pluck string 2 64 { 65 NOWnote=note2; 66 Onetime[2]=1; // played and waits untill ur the finger is off 67 } 68 MIDI.sendNoteOn(NOWnote,127,0); 69 delay(DELAY); //play note: meaning pluck 70 } 71 else // find the right note 72 { 73 note0=find_note(PlayNote,0); 74 note1=find_note(PlayNote,1); 75 note2=find_note(PlayNote,2); 76 } 77 78 for(int i=0;i<strings;i++)// resets the logic test 79 { 80 if (PlayNote[i]==0) 81 { 82 Onetime[i]=0; 83 } 84 } 85} 86//****************************************************************************************************** 87//Find MIDI note 88//****************************************************************************************************** 89int find_note(int PlayNote[9] ,int string ) 90{ 91int AllNote[3][3] ={ {50,68,69} , {62,63,64} , {66,67,68} }; // order is importent 92int note=-2; 93int j=0; 94int notes[ ]={50,68,69}; 95int Play[]={0,0}; 96//loading the notes 97for (int i=0;i<4;i++) 98{ 99notes[i]=AllNote[string][i]; 100} 101//take the frets input 102for (int i=2*string+3;i<2*string+5;i++) //loading the inputs 103{ 104Play[j]=PlayNote[i]; 105j++; 106} 107//logic 108 if (Play[1]==0 && Play[2]==0) // no fretting 109 { 110 note=notes[0]; //open string 111 } 112 else if (Play[0]==1 && Play[1]==1) // fret 1 which blocks two LDRs in a row 113 { 114 note=notes[1]; //first fret is pressed 115 } 116 else if (Play[0]==0 && Play[1]==1 ) // fret 2 which only blocks last LDR in a row 117 { 118 note=notes[2]; //second fret is pressed 119 } 120 else 121 { 122 // error=true; 123 note=-2; 124 } 125 return note; 126} 127[/code]
Downloadable files
Circuit Design
Circuit Design
Comments
Only logged in users can leave comments