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:
- 4:e370f322a697
- Parent:
- 3:c672e782f19b
- Child:
- 5:c0fd99f07536
--- a/main.cpp Mon Apr 16 22:29:41 2012 +0000 +++ b/main.cpp Mon Apr 16 23:17:49 2012 +0000 @@ -66,10 +66,6 @@ device_init();//Setup buttons and set global variables - lcd.cls(); - lcd.printf("finish device_init"); - wait(.5); - int state=0,next_state=0; //float old_freq=0; float new_freq=0; @@ -79,7 +75,6 @@ output_menu(); while (1) { - state=next_state; switch (state) { @@ -132,9 +127,6 @@ //----------------------------------------- case 4://Winding mode if (current_mode==winding_mode) { - lcd.cls(); - lcd.printf("Winding Mode"); - if (wind_up) { motor.motor_turn(up,5);//TODO:Adjust number of turns } @@ -154,7 +146,8 @@ if (start_tuning==false) {//If the stop button is pressed, the state machine returns to user input next_state=0; - + //setup_buttons(); + //output_menu(); } if (current_mode==winding_mode) {//TODO:Debug this @@ -176,13 +169,13 @@ //Display the string and pitch selection menu void output_menu() { lcd.cls(); - lcd.printf("Select String: %d",selected_string); - + lcd.printf("Select String: %d",selected_string+1); + lcd.locate(0,1); strings *temp=&strings_array[selected_string]; lcd.printf("Select Pitch: "); - lcd.printf(temp->get_note().c_str()); - wait(.1); + lcd.printf("%s",temp->get_note());//temp->get_note().c_str());TODO:Fix!!!! + wait(.5); } //*************************************************** @@ -199,6 +192,8 @@ mode_but.mode( PullDown ); mode_but.setSampleFrequency(); + + setup_buttons(); } //*************************************************** @@ -224,8 +219,8 @@ //Change the selected string - there are only six strings void string_sel() { selected_string++; - if (selected_string>6) - selected_string=1; + if (selected_string>5) + selected_string=0; output_menu(); } @@ -253,12 +248,15 @@ current_mode=winding_mode; lcd.cls(); lcd.printf("Winding Mode"); - wait(.5); + wait(1); + lcd.cls(); + lcd.printf("Start for up\nStop for down"); } else { current_mode=tuning_mode; lcd.cls(); lcd.printf("Tuning Mode"); wait(.5); + output_menu(); } setup_buttons();//Change the functions the buttons connect to } @@ -295,13 +293,6 @@ strings string4(4); strings string5(5); strings string6(6); - /* strings_array.push_back(string1); - strings_array.push_back(string2); - strings_array.push_back(string3); - strings_array.push_back(string4); - strings_array.push_back(string5); - strings_array.push_back(string6); - */ strings_array[0]=string1; strings_array[1]=string2; @@ -310,11 +301,7 @@ strings_array[4]=string5; strings_array[5]=string6; - lcd.cls(); - lcd.printf("device init"); - wait(.5); - - selected_string=6; + selected_string=5; current_mode=tuning_mode; start_tuning=false; up=true; @@ -336,6 +323,7 @@ bool done=false; lcd.cls(); lcd.printf("Please pluck\nstring"); + wait(1); //motor.motor_turn(up,25)//TODO: Adjust the number of steps here //On second thought, we don't need to tune up and down for this, we can find the current frequency @@ -348,6 +336,9 @@ freq_up=freq; done=true; } + + if (start_tuning==false) + break; } motor.motor_turn(down,25);//TODO: Adjust the number of steps here done=false; @@ -359,6 +350,8 @@ freq_down=freq; done=true; } + if (start_tuning==false) + break; } if (freq_up<freq_down) { @@ -368,6 +361,11 @@ lcd.cls(); lcd.printf("Calibration Done"); + + if (start_tuning==false) { + output_menu(); + setup_buttons(); + } } //********************************************** bool check_threshold(float freq) {