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

Dependencies:   FFT FrequencyFinder Motor NewTextLCD PinDetect mbed strings

Revision:
7:057bcd99a3f8
Parent:
6:46fb12f6ace1
Child:
8:651fbf5ae98a
--- a/main.cpp	Thu Apr 19 20:31:42 2012 +0000
+++ b/main.cpp	Fri Apr 20 17:28:27 2012 +0000
@@ -18,9 +18,9 @@
 //DigitalOut led2(LED2);
 
 TextLCD lcd(p5,p6,p7,p8,p9,p10);//Our method of communication with LCD screen (rs e d4 d5 d6 d7)
-Motor motor(p24,p20,p21);//Setup for the motor (enable, direction, step)
-FrequencyFinder guitar(p18);//Interface to get data from guitar (input pin)
-
+Motor motor(p24,p19,p21);//Setup for the motor (enable, direction, step)
+FrequencyFinder guitar(p20);//Interface to get data from guitar (input pin)
+AnalogOut bias(p18);//1.6v DC offset
 
 DigitalOut ledBlue(p25);
 DigitalOut ledGreen(p23);
@@ -32,7 +32,7 @@
 bool start_tuning;//Bool to tell whether to start the tuning process or not
 bool wind_up;//Bool for winding mode - turn motor up
 bool wind_down;//Bool for winding mode - turn motor down
-bool up, down;//To move the motor up or down
+short up, down;//To move the motor up or down
 
 //vector<strings> strings_array;//Holds strings objects - basically the frequency data for each string
 strings strings_array[6];
@@ -71,7 +71,7 @@
     lcd.cls();//Clear the LCD
     lcd.printf("Perfect\n      Pitch");//Modify to whatever we want to name this thing
     LED_initialize();
-    wait(.5);
+
 
     device_init();//Setup buttons and set global variables
 
@@ -80,6 +80,7 @@
     float new_freq=0;
     float desired_freq=0;
     strings *temp=&strings_array[0];
+    wait(.5);
 
     output_menu();
 
@@ -147,6 +148,10 @@
                     }
                     next_state=4;
                 } else {
+                    output_menu();
+                    wind_up=false;
+                    wind_down=false;
+                    setup_buttons();
                     next_state=0;
                 }
                 break;
@@ -167,9 +172,16 @@
 
         if (start_tuning) {
             lcd.cls();
-            lcd.printf("Detected %f ",new_freq);
+
+            lcd.locate(9,0);
+            lcd.printf("%f",new_freq);
+            lcd.locate(9,1);
+            lcd.printf("%f",desired_freq);
+
             lcd.locate(0,1);
-            lcd.printf("Desired %f",desired_freq);
+            lcd.printf("Desired");
+            lcd.locate(0,0);
+            lcd.printf("Detected");
         }
 
     }//end while
@@ -281,6 +293,9 @@
 //***************************************************
 void stop() {
     start_tuning=false;
+
+    output_menu();
+    setup_buttons();
 }
 //***************************************************
 void do_nothing() {
@@ -322,9 +337,11 @@
     selected_string=5;
     current_mode=tuning_mode;
     start_tuning=false;
-    up=true;
-    down=false;
-    wind_up=true;
+    up=1;
+    down=0;
+    wind_up=false;
+    wind_down=false;
+    bias=.5;
 
     button_init();
 
@@ -373,8 +390,8 @@
     }
 
     if (freq_up<freq_down) {
-        down=true;
-        up=false;
+        down=1;
+        up=0;
     }
 
     lcd.cls();
@@ -437,25 +454,25 @@
     //ledRed=2;
     //ledGreen=3;
     //value must be an int: 0 or 1
- if(value!=0)
+    if (value!=0)
 
-    switch (led) {
-        case(1):
-            ledBlue=value;
-            break;
+        switch (led) {
+            case(1):
+                ledBlue=value;
+                break;
 
-        case(2):
-            ledRed=value;
-            break;
+            case(2):
+                ledRed=value;
+                break;
 
-        case(3):
-            ledGreen=value;
-            break;
+            case(3):
+                ledGreen=value;
+                break;
 
-        default:
-            break;
+            default:
+                break;
 
-    }
+        }
 
     return;