![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A program to automatically tune a guitar. Written by Justin Reidhead and Steven Swenson
Dependencies: FFT FrequencyFinder Motor NewTextLCD PinDetect mbed strings
Diff: main.cpp
- Revision:
- 11:bdad1acccdad
- Parent:
- 9:2a211133e79a
- Child:
- 12:03c189de6e2e
--- 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