A program to automatically tune a guitar. Written by Justin Reidhead and Steven Swenson
Dependencies: FFT FrequencyFinder Motor NewTextLCD PinDetect mbed strings
main.cpp@0:d8909ac31fbf, 2012-04-15 (annotated)
- Committer:
- melangeaddict
- Date:
- Sun Apr 15 00:20:28 2012 +0000
- Revision:
- 0:d8909ac31fbf
- Child:
- 1:4a82a5178506
Before pasting in from QT
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
melangeaddict | 0:d8909ac31fbf | 1 | #include "mbed.h" |
melangeaddict | 0:d8909ac31fbf | 2 | |
melangeaddict | 0:d8909ac31fbf | 3 | //Button interrupts |
melangeaddict | 0:d8909ac31fbf | 4 | InterruptIn start_stop_b(p5); |
melangeaddict | 0:d8909ac31fbf | 5 | InterruptIn pitch_b(p6); |
melangeaddict | 0:d8909ac31fbf | 6 | InterruptIn string_b(p7); |
melangeaddict | 0:d8909ac31fbf | 7 | InterruptIn mode_b(p8); |
melangeaddict | 0:d8909ac31fbf | 8 | |
melangeaddict | 0:d8909ac31fbf | 9 | // |
melangeaddict | 0:d8909ac31fbf | 10 | |
melangeaddict | 0:d8909ac31fbf | 11 | //AnalogIn |
melangeaddict | 0:d8909ac31fbf | 12 | AnalogIn guitar(p20); |
melangeaddict | 0:d8909ac31fbf | 13 | |
melangeaddict | 0:d8909ac31fbf | 14 | //Motor Controller outputs |
melangeaddict | 0:d8909ac31fbf | 15 | PwmOut step(p26); |
melangeaddict | 0:d8909ac31fbf | 16 | DigitalOut direction(p27); |
melangeaddict | 0:d8909ac31fbf | 17 | DigitalOut motor_enable(p28); |
melangeaddict | 0:d8909ac31fbf | 18 | |
melangeaddict | 0:d8909ac31fbf | 19 | //Local File pointer |
melangeaddict | 0:d8909ac31fbf | 20 | LocalFileSystem local("local"); |
melangeaddict | 0:d8909ac31fbf | 21 | |
melangeaddict | 0:d8909ac31fbf | 22 | //Global Variables |
melangeaddict | 0:d8909ac31fbf | 23 | bool begin=false; |
melangeaddict | 0:d8909ac31fbf | 24 | |
melangeaddict | 0:d8909ac31fbf | 25 | |
melangeaddict | 0:d8909ac31fbf | 26 | //Functions |
melangeaddict | 0:d8909ac31fbf | 27 | void device_init(){ |
melangeaddict | 0:d8909ac31fbf | 28 | return;} |
melangeaddict | 0:d8909ac31fbf | 29 | |
melangeaddict | 0:d8909ac31fbf | 30 | void start(){ |
melangeaddict | 0:d8909ac31fbf | 31 | begin=true; |
melangeaddict | 0:d8909ac31fbf | 32 | return;} |
melangeaddict | 0:d8909ac31fbf | 33 | |
melangeaddict | 0:d8909ac31fbf | 34 | void stop(){ |
melangeaddict | 0:d8909ac31fbf | 35 | return;} |
melangeaddict | 0:d8909ac31fbf | 36 | |
melangeaddict | 0:d8909ac31fbf | 37 | void pitch(){ |
melangeaddict | 0:d8909ac31fbf | 38 | return;} |
melangeaddict | 0:d8909ac31fbf | 39 | |
melangeaddict | 0:d8909ac31fbf | 40 | void string(){ |
melangeaddict | 0:d8909ac31fbf | 41 | return;} |
melangeaddict | 0:d8909ac31fbf | 42 | |
melangeaddict | 0:d8909ac31fbf | 43 | void mode(){ |
melangeaddict | 0:d8909ac31fbf | 44 | return;} |
melangeaddict | 0:d8909ac31fbf | 45 | |
melangeaddict | 0:d8909ac31fbf | 46 | |
melangeaddict | 0:d8909ac31fbf | 47 | |
melangeaddict | 0:d8909ac31fbf | 48 | int main() { |
melangeaddict | 0:d8909ac31fbf | 49 | int state=0, next_state=0; |
melangeaddict | 0:d8909ac31fbf | 50 | |
melangeaddict | 0:d8909ac31fbf | 51 | |
melangeaddict | 0:d8909ac31fbf | 52 | start_stop_b.rise(&start);//Assign what functions to call when |
melangeaddict | 0:d8909ac31fbf | 53 | pitch_b.rise(&pitch); //the interrupt occurs |
melangeaddict | 0:d8909ac31fbf | 54 | string_b.rise(&string); |
melangeaddict | 0:d8909ac31fbf | 55 | mode_b.rise(&mode); |
melangeaddict | 0:d8909ac31fbf | 56 | |
melangeaddict | 0:d8909ac31fbf | 57 | device_init(); |
melangeaddict | 0:d8909ac31fbf | 58 | |
melangeaddict | 0:d8909ac31fbf | 59 | |
melangeaddict | 0:d8909ac31fbf | 60 | while (1) { |
melangeaddict | 0:d8909ac31fbf | 61 | state=next_state; |
melangeaddict | 0:d8909ac31fbf | 62 | switch (state) { |
melangeaddict | 0:d8909ac31fbf | 63 | case(0)://Waiting for user input |
melangeaddict | 0:d8909ac31fbf | 64 | if(begin){ |
melangeaddict | 0:d8909ac31fbf | 65 | next_state=1; |
melangeaddict | 0:d8909ac31fbf | 66 | } |
melangeaddict | 0:d8909ac31fbf | 67 | else |
melangeaddict | 0:d8909ac31fbf | 68 | next_state=0; |
melangeaddict | 0:d8909ac31fbf | 69 | break; |
melangeaddict | 0:d8909ac31fbf | 70 | case(1)://Take Sample |
melangeaddict | 0:d8909ac31fbf | 71 | break; |
melangeaddict | 0:d8909ac31fbf | 72 | case(2)://Take FFT |
melangeaddict | 0:d8909ac31fbf | 73 | break; |
melangeaddict | 0:d8909ac31fbf | 74 | case(3)://Analyze FFT for Peaks |
melangeaddict | 0:d8909ac31fbf | 75 | break; |
melangeaddict | 0:d8909ac31fbf | 76 | case(4)://Compare current freq with desired |
melangeaddict | 0:d8909ac31fbf | 77 | //Determine Hz per step |
melangeaddict | 0:d8909ac31fbf | 78 | break; |
melangeaddict | 0:d8909ac31fbf | 79 | case(5)://Motor Direction Calibration |
melangeaddict | 0:d8909ac31fbf | 80 | break; |
melangeaddict | 0:d8909ac31fbf | 81 | case(6)://Step Up |
melangeaddict | 0:d8909ac31fbf | 82 | break; |
melangeaddict | 0:d8909ac31fbf | 83 | case(7)://Step Down |
melangeaddict | 0:d8909ac31fbf | 84 | break; |
melangeaddict | 0:d8909ac31fbf | 85 | default: |
melangeaddict | 0:d8909ac31fbf | 86 | break; |
melangeaddict | 0:d8909ac31fbf | 87 | } |
melangeaddict | 0:d8909ac31fbf | 88 | |
melangeaddict | 0:d8909ac31fbf | 89 | } |
melangeaddict | 0:d8909ac31fbf | 90 | } |
melangeaddict | 0:d8909ac31fbf | 91 | |
melangeaddict | 0:d8909ac31fbf | 92 |