Appendix A:
Code for Main Body's Arduinoconst int string[] = {5,4,3,2,1,10};//10,1,2,3,4,5};
int stringval[6];
int pos[6];
const int position = 6;
int dir = 12;
int pwm = 13;
int direct = 7;
int i = 0, q = 0;
int j = 0;
float k = 1;
int dir1 = 0;
int vol = 0, xval=500, var=0;
const int commout = 3, xaxis=8, yaxis=9;
int pitch = (255-146)/2;
void setup() {
Serial.begin(31250);
pinMode(direct,INPUT);
pinMode(pwm,OUTPUT);
pinMode(dir,OUTPUT);
}
void comm(int x, int a, int y, int z, int b){
if (x <> 50)
{
//Sends a MIDI signal and the other Arduino a signal
if ((x-a+3 > z-a-3)) {
noteOn(0x90,16*(z/(1023/7)-1)+stringval[z/(1023/7)-1],b);
analogWrite(commout,map(vol,70,110,0,150));
delay(15);
}
else if (a-x+3 > a-(z-1023/7)-3) {
noteOn(0x90,16*(z/(1023/7)-2)+stringval[z/(1023/7)-2],b);
analogWrite(commout,map(vol,70,110,0,150));
delay(15);
}
//Creates a feedback for the user (virtual spring)
if (y <495){>525)
{
if (x>z-1023/14+15) {
analogWrite(pwm,0);
} else {
analogWrite(pwm,abs(z-x)*k);
analogWrite(dir, 255);
}
}
}
else {
analogWrite(pwm,1);
}
}
void noteOn(byte cmd, byte data1, byte data2) {
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
// Serial.print("cmd ");
// Serial.print(cmd, HEX);
// Serial.print(" data1 ");
// Serial.print(data1, HEX);
// Serial.print(" vol ");
// Serial.println(data2, HEX);
}
void loop() {
//reads the value of each string to determine fret position
i=i+1;
q=q+1;
if (i==6) {
i=0;
}
stringval[i]=map(analogRead(string[i]),-14,970,0,15);///(1023/15);
//reads the position of the fader and direction it's traveling
pos[i] = analogRead(position);
dir1 = analogRead(7);
vol = map(analogRead(xaxis),295,400,110,70);
if (i==0) { j = 5; }
else { j = i-1; }
//Sends the position, past position, direction, string it's closet to, and the volumn to the
//commuication function
if (pos[i] <= 1023/7) { comm(pos[i],pos[j],dir1,1023/7,vol); }else if (pos[i] <= 2*1023/7) { comm(pos[i],pos[j],dir1,2*1023/7,vol); } else if (pos[i] <= 3*1023/7) { comm(pos[i],pos[j],dir1,3*1023/7,vol); } else if (pos[i] <= 4*1023/7) { comm(pos[i],pos[j],dir1,4*1023/7,vol); } else if (pos[i] <= 5*1023/7) { comm(pos[i],pos[j],dir1,5*1023/7,vol); } else if (pos[i] <= 6*1023/7) { comm(pos[i],pos[j],dir1,6*1023/7,vol); } else { comm(pos[i],pos[j],dir1,7*1023/7,vol); } //sends the other Arduino a constant flat line analogWrite(commout,1); }
Code for Arduino at Head of Guitar: int i = 0; int var = 0; int varLed1 = 0; int varLed2 = 0; int varLed3 = 0; int myData = 0;
int ledPin1 = 3; int ledPin2 = 5; int ledPin3 = 6; int motorPin1 = 11; int motorPin2 = 10; int volInput = 1;
void setup(){
Serial.begin(38400);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
}
void loop() {
myData = analogRead(volInput);
Serial.println(myData);
if(myData > 50) { i = 0;}
var = map(myData, 0, 900, 0, 255);
varLed1 = map(myData, 0, 900, 0, 255);
varLed2 = map(myData, 0, 900, 0, 175);
varLed3 = map(myData, 0, 900, 0, 125);
if(i <255){
analogWrite(motorPin1, var-i);
analogWrite(motorPin2, var-i);
analogWrite(ledPin1, varLed1-i);
if(i <125){
analogWrite(ledPin2, varLed2-i);
analogWrite(ledPin3, varLed3-i);
}
else if(i <175){
analogWrite(ledPin2, varLed2-i);
analogWrite(ledPin3, 1);
}
else if(i <255){
analogWrite(ledPin2, 1);
analogWrite(ledPin3, 1);
}
delay(5);
i = i + 1;
}
else{
analogWrite(motorPin1, 1);
analogWrite(motorPin2, 1);
analogWrite(ledPin1, 1);
analogWrite(ledPin2, 1);
analogWrite(ledPin3, 1);
}
}