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:
- 5:c0fd99f07536
- Parent:
- 4:e370f322a697
- Child:
- 6:46fb12f6ace1
--- a/main.cpp Mon Apr 16 23:17:49 2012 +0000 +++ b/main.cpp Tue Apr 17 19:46:33 2012 +0000 @@ -14,12 +14,12 @@ PinDetect start_but(p13); PinDetect mode_but(p14); -DigitalOut led1(LED1);//For diagnostic purposes -DigitalOut led2(LED2); +//DigitalOut led1(LED1);//For diagnostic purposes +//DigitalOut led2(LED2); -TextLCD lcd(p23,p24,p25,p26,p27,p28);//Our method of communication with LCD screen (rs e d4 d5 d6 d7) -Motor motor(p20,p21,p22);//Setup for the motor (enable, direction, step) -FrequencyFinder guitar(p19);//Interface to get data from guitar (input pin) +TextLCD lcd(p10,p9,p8,p7,p6,p5);//Our method of communication with LCD screen (rs e d4 d5 d6 d7) +Motor motor(p19,p20,p21);//Setup for the motor (enable, direction, step) +FrequencyFinder guitar(p18);//Interface to get data from guitar (input pin) short selected_string;//Holds on to the selected string bool current_mode;//Tuning mode or winding mode @@ -105,16 +105,18 @@ 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 lcd.cls(); - lcd.printf("String %d\ntuned",selected_string); + lcd.printf("String %d\ntuned",selected_string+1); wait(.5); start_tuning=false; + output_menu(); + setup_buttons(); next_state=0; } else if ((desired_freq-.5)>new_freq) {//We are too low, and need to turn the string tigher - //motor(up,# of steps); + motor.motor_turn(up,10);//TODO:Adjust # of steps next_state=3; } else {//We are too high, and need to loosen the string - //motor(down,# of steps); + motor.motor_turn(down,10); next_state=3; } } else { @@ -156,7 +158,9 @@ if (start_tuning) { lcd.cls(); - lcd.printf("Detected %f\nDesired %f",new_freq,desired_freq); + lcd.printf("Detected %f ",new_freq); + lcd.locate(0,1); + lcd.printf("Desired %f",desired_freq); } }//end while @@ -174,8 +178,8 @@ lcd.locate(0,1); strings *temp=&strings_array[selected_string]; lcd.printf("Select Pitch: "); - lcd.printf("%s",temp->get_note());//temp->get_note().c_str());TODO:Fix!!!! - wait(.5); + lcd.printf("%s",temp->get_note()); + //wait(.5); } //*************************************************** @@ -222,6 +226,9 @@ if (selected_string>5) selected_string=0; + strings *temp=&strings_array[selected_string]; + temp->reset_index(); + output_menu(); } //*************************************************** @@ -238,7 +245,9 @@ start_tuning=true; string_but.attach_asserted(&do_nothing);//Disable the other buttons + string_but.attach_deasserted(&do_nothing); pitch_but.attach_asserted(&do_nothing); + pitch_but.attach_deasserted(&do_nothing); start_but.attach_asserted(&stop); //except for the start/stop button mode_but.attach_asserted(&do_nothing); } @@ -250,7 +259,7 @@ lcd.printf("Winding Mode"); wait(1); lcd.cls(); - lcd.printf("Start for up\nStop for down"); + lcd.printf("String for up\nPitch for down"); } else { current_mode=tuning_mode; lcd.cls();