A program to automatically tune a guitar. Written by Justin Reidhead and Steven Swenson

Dependencies:   FFT FrequencyFinder Motor NewTextLCD PinDetect mbed strings

Files at this revision

API Documentation at this revision

Comitter:
melangeaddict
Date:
Wed Apr 25 00:42:46 2012 +0000
Parent:
10:4566e8aeb3ae
Child:
12:03c189de6e2e
Commit message:
messed with gains of the strings;

Changed in this revision

FrequencyFinder/FrequencyFinder.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/FrequencyFinder/FrequencyFinder.cpp	Tue Apr 24 23:20:53 2012 +0000
+++ b/FrequencyFinder/FrequencyFinder.cpp	Wed Apr 25 00:42:46 2012 +0000
@@ -43,16 +43,18 @@
 //takes the absolute value of the signal
     for (int j=0; j<size; j++) {
         signal_array[j]=abs(signal_array[j]);
-        if (j<100)
+        if (j<200)//~48Hz
             signal_array[j]=0;
-        else if (j<400)
+        else if (j<400)//~97Hz
             signal_array[j]=signal_array[j]*5;
-        else if (j<600)
+        else if (j<600)//~146Hz
             signal_array[j]=signal_array[j]*6;
-        else if (j<800)
+        else if (j<900)//~219Hz
             signal_array[j]=signal_array[j]*7;
+        else if (j<1200)//292Hz
+            signal_array[j]=signal_array[j]*25;
         else
-            signal_array[j]=signal_array[j]*10;
+            signal_array[j]=signal_array[j]*30;
     }
 }
 
--- a/main.cpp	Tue Apr 24 23:20:53 2012 +0000
+++ b/main.cpp	Wed Apr 25 00:42:46 2012 +0000
@@ -72,15 +72,16 @@
     lcd.cls();//Clear the LCD
     lcd.printf("Perfect\n      Pitch");//Modify to whatever we want to name this thing
     LED_initialize();
-   // wait(.5);
+    // wait(.5);
 
     device_init();//Setup buttons and set global variables
 
-    
+
 
     int state=0,next_state=0;
-    int num_steps=0;
-    float old_freq=0;
+    //int num_steps=0;
+    //float old_freq=0;
+    //int found_frequency=0;
     float new_freq=0;
     float desired_freq=0;
     strings *temp=&strings_array[0];
@@ -110,7 +111,7 @@
             case 2://begin the actual tuning
                 temp=&strings_array[selected_string];
                 desired_freq=temp->get_freq();//Get the desired frequency for the string selected
-                old_freq=desired_freq;//We have to initalize it to something...
+                //old_freq=desired_freq;//We have to initalize it to something...
 
                 next_state=3;
                 break;
@@ -127,6 +128,13 @@
 
                 if (check_threshold(new_freq)) {//The check_threshold function makes sure the frequency is valid (less than 500 Hz)
                     if ((desired_freq-.5)<new_freq && (desired_freq+.5)>new_freq) {//We are within .5Hz of the desired frequency
+
+                        //if (found_frequency==0) {
+                        //    found_frequency++;
+                        //    next_state=3;
+                        //    break;
+                        //}
+
                         lcd.cls();
                         lcd.printf("String %d\ntuned",selected_string+1);
                         set_LED(1,0);//blue on
@@ -146,6 +154,7 @@
                         set_LED(2,0);//red on;
                         set_LED(3,1);//green off
 
+                        //found_frequency=0;
 
                         wait(.5);
 
@@ -158,6 +167,9 @@
                         set_LED(1,1);//blue off
                         set_LED(2,1);//red off;
                         set_LED(3,0);//green on
+
+                        //found_frequency=0;
+
                         wait(.5);
 
                         motor.motor_turn(down,10);
@@ -192,6 +204,7 @@
                     wind_up=false;
                     wind_down=false;
                     setup_buttons();
+                    //set_LED(1,0);
                     next_state=0;
                 }
                 break;
@@ -241,6 +254,10 @@
     lcd.printf("Select Pitch: ");
     lcd.printf("%s",temp->get_note());
     //wait(.5);
+    
+    set_LED(1,0);//Turn blue LED on
+    set_LED(2,1);
+    set_LED(3,1);
 }
 
 //***************************************************
@@ -449,9 +466,18 @@
 bool check_threshold(float freq) {
     strings *temp=&strings_array[selected_string];
     float desired_freq=temp->get_freq();//Get the desired frequency for the string selected
+    
     if (freq>(desired_freq+75) || freq<(desired_freq-75) || freq>500) {//new_freq>(desired_freq+50) || new_freq<(desired_freq-50)
         lcd.cls();
-        lcd.printf("Pluck string \nagain");
+        lcd.printf("Pluck string %d\nagain",selected_string+1);
+        
+        set_LED(1,1);
+        set_LED(2,1);
+        set_LED(3,1);//Turn led off
+        
+        set_LED(2,0);
+        set_LED(3,0);//Make the LED turn yellow
+        
         wait(.5);
         return false;
     } else