![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
School project for big bang base code
Fork of GT_Tuner3 by
main.cpp@1:c8ec50d75f80, 2017-01-30 (annotated)
- Committer:
- mptapton
- Date:
- Mon Jan 30 13:16:23 2017 +0000
- Revision:
- 1:c8ec50d75f80
- Parent:
- 0:6b0b61d411ad
- Child:
- 2:4be1b96a5a34
Solo school project mbed 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mptapton | 0:6b0b61d411ad | 1 | // Guitar Tuner and Chord Learning Tool using Goertzel's Algorithm // |
mptapton | 0:6b0b61d411ad | 2 | // Based on original code created by: Andrew Durand // |
mptapton | 0:6b0b61d411ad | 3 | // Adjusted and modified by Tapton School EDS Project Team // |
mptapton | 0:6b0b61d411ad | 4 | |
mptapton | 0:6b0b61d411ad | 5 | #include "TextLCD.h" |
mptapton | 0:6b0b61d411ad | 6 | #include "mbed.h" |
mptapton | 0:6b0b61d411ad | 7 | #include "adc.h" |
mptapton | 0:6b0b61d411ad | 8 | #include <math.h> |
mptapton | 0:6b0b61d411ad | 9 | #define PI 3.1415 |
mptapton | 0:6b0b61d411ad | 10 | #define SAMPLE_RATE 24000 |
mptapton | 0:6b0b61d411ad | 11 | |
mptapton | 0:6b0b61d411ad | 12 | DigitalOut led_low(LED1); |
mptapton | 0:6b0b61d411ad | 13 | DigitalOut led_ok(LED2); |
mptapton | 0:6b0b61d411ad | 14 | DigitalOut led_high(LED4); |
mptapton | 0:6b0b61d411ad | 15 | InterruptIn button1(p6); //mosi |
mptapton | 0:6b0b61d411ad | 16 | DigitalIn myInputPin (p21); //select tuner or chord learning mode |
mptapton | 1:c8ec50d75f80 | 17 | Serial device(p28, p27); // tx, rx to connect to mbed 2 |
mptapton | 0:6b0b61d411ad | 18 | |
mptapton | 0:6b0b61d411ad | 19 | //LCD and Other Random Variables |
mptapton | 0:6b0b61d411ad | 20 | //NokiaLCD lcd(p5, p7, p8, p9, NokiaLCD::LCD6610); // mosi, sclk, cs, rst, type |
mptapton | 0:6b0b61d411ad | 21 | |
mptapton | 0:6b0b61d411ad | 22 | /* This code uses libraries created for 4-bit LCD's based on the HD44780. This |
mptapton | 0:6b0b61d411ad | 23 | program was designed for a similar product (Winstar's WH1602B 2x16 LC) working |
mptapton | 0:6b0b61d411ad | 24 | into an Mbed LPC1768. |
mptapton | 0:6b0b61d411ad | 25 | LCD pins: Pin 1(VSS) to Mbed Gnd, Pin 2(VDD) to Mbed 5v USB output, Pin 3(Vo- contrast) |
mptapton | 0:6b0b61d411ad | 26 | to Mbed Gnd (via a 4k7 resistor), Pin 5(R/W) to Mbed Gnd, Pin 15(A)to Mbed 5v USB output, Pin 16(B) to |
mptapton | 0:6b0b61d411ad | 27 | MBed Gnd, Pins 4(RS),20(E) and the 4 data bits (DB4 [11] through to DB7 [14]) |
mptapton | 0:6b0b61d411ad | 28 | go to the Mbed pins described below: */ |
mptapton | 0:6b0b61d411ad | 29 | |
mptapton | 0:6b0b61d411ad | 30 | TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d4-d7 |
mptapton | 0:6b0b61d411ad | 31 | |
mptapton | 0:6b0b61d411ad | 32 | int string_select = 0; |
mptapton | 0:6b0b61d411ad | 33 | int chord_select = 0; |
mptapton | 0:6b0b61d411ad | 34 | float high, high1, in_tune, in_tune1, in_tune2, in_tune3, |
mptapton | 0:6b0b61d411ad | 35 | low, low1, note, low_mod, high_mod; |
mptapton | 0:6b0b61d411ad | 36 | char* key; |
mptapton | 0:6b0b61d411ad | 37 | int Counter = 0; |
mptapton | 0:6b0b61d411ad | 38 | int Buffer[6000]; |
mptapton | 0:6b0b61d411ad | 39 | |
mptapton | 0:6b0b61d411ad | 40 | float goertzelFilter(int samples[], float freq, int N) { |
mptapton | 0:6b0b61d411ad | 41 | float s_prev = 0.0; |
mptapton | 0:6b0b61d411ad | 42 | float s_prev2 = 0.0; |
mptapton | 0:6b0b61d411ad | 43 | float coeff,normalizedfreq,power,s; |
mptapton | 0:6b0b61d411ad | 44 | int i; |
mptapton | 0:6b0b61d411ad | 45 | normalizedfreq = freq / SAMPLE_RATE; |
mptapton | 0:6b0b61d411ad | 46 | coeff = 2*cos(2*PI*normalizedfreq); |
mptapton | 0:6b0b61d411ad | 47 | for (i=0; i<N; i++) { |
mptapton | 0:6b0b61d411ad | 48 | s = samples[i] + coeff * s_prev - s_prev2; |
mptapton | 0:6b0b61d411ad | 49 | s_prev2 = s_prev; |
mptapton | 0:6b0b61d411ad | 50 | s_prev = s; |
mptapton | 0:6b0b61d411ad | 51 | } |
mptapton | 0:6b0b61d411ad | 52 | power = s_prev2*s_prev2+s_prev*s_prev-coeff*s_prev*s_prev2; |
mptapton | 0:6b0b61d411ad | 53 | return power; |
mptapton | 0:6b0b61d411ad | 54 | } |
mptapton | 0:6b0b61d411ad | 55 | |
mptapton | 0:6b0b61d411ad | 56 | ADC adc(SAMPLE_RATE, 1); |
mptapton | 0:6b0b61d411ad | 57 | |
mptapton | 0:6b0b61d411ad | 58 | void sample_audio(int chan, uint32_t value) { |
mptapton | 0:6b0b61d411ad | 59 | Buffer[Counter] = adc.read(p20); |
mptapton | 0:6b0b61d411ad | 60 | Counter += 1; |
mptapton | 0:6b0b61d411ad | 61 | } |
mptapton | 0:6b0b61d411ad | 62 | |
mptapton | 0:6b0b61d411ad | 63 | void button1_pressed() { |
mptapton | 0:6b0b61d411ad | 64 | string_select++; |
mptapton | 0:6b0b61d411ad | 65 | chord_select++; |
mptapton | 0:6b0b61d411ad | 66 | if (string_select > 5) string_select = 0; |
mptapton | 0:6b0b61d411ad | 67 | if (chord_select > 9) chord_select = 0;//change for number of chords supported |
mptapton | 0:6b0b61d411ad | 68 | } |
mptapton | 0:6b0b61d411ad | 69 | |
mptapton | 0:6b0b61d411ad | 70 | int main() { |
mptapton | 1:c8ec50d75f80 | 71 | device.baud(19200); |
mptapton | 0:6b0b61d411ad | 72 | while (1) { |
mptapton | 0:6b0b61d411ad | 73 | myInputPin.mode(PullUp); //set the mbed to use a pullup resistor |
mptapton | 0:6b0b61d411ad | 74 | if (myInputPin) { //select guitar tuner or chord teaching |
mptapton | 0:6b0b61d411ad | 75 | lcd.cls (); // Guitar Tuner Section based on p21 being +3v |
mptapton | 0:6b0b61d411ad | 76 | |
mptapton | 0:6b0b61d411ad | 77 | //Interupt for Switching Strings |
mptapton | 0:6b0b61d411ad | 78 | button1.mode(PullDown); |
mptapton | 0:6b0b61d411ad | 79 | button1.rise(&button1_pressed); |
mptapton | 0:6b0b61d411ad | 80 | |
mptapton | 0:6b0b61d411ad | 81 | while (1) { |
mptapton | 0:6b0b61d411ad | 82 | |
mptapton | 0:6b0b61d411ad | 83 | switch (string_select) { |
mptapton | 0:6b0b61d411ad | 84 | case 0: |
mptapton | 0:6b0b61d411ad | 85 | note = 82; |
mptapton | 0:6b0b61d411ad | 86 | key= "E2"; |
mptapton | 0:6b0b61d411ad | 87 | break; |
mptapton | 0:6b0b61d411ad | 88 | case 1: |
mptapton | 0:6b0b61d411ad | 89 | note = 110; |
mptapton | 0:6b0b61d411ad | 90 | key= "A2"; |
mptapton | 0:6b0b61d411ad | 91 | break; |
mptapton | 0:6b0b61d411ad | 92 | case 2: |
mptapton | 0:6b0b61d411ad | 93 | note = 147; |
mptapton | 0:6b0b61d411ad | 94 | key= "D3"; |
mptapton | 0:6b0b61d411ad | 95 | break; |
mptapton | 0:6b0b61d411ad | 96 | case 3: |
mptapton | 0:6b0b61d411ad | 97 | note = 196; |
mptapton | 0:6b0b61d411ad | 98 | key= "G3"; |
mptapton | 0:6b0b61d411ad | 99 | break; |
mptapton | 0:6b0b61d411ad | 100 | case 4: |
mptapton | 0:6b0b61d411ad | 101 | note = 247; |
mptapton | 0:6b0b61d411ad | 102 | key= "B3"; |
mptapton | 0:6b0b61d411ad | 103 | break; |
mptapton | 0:6b0b61d411ad | 104 | case 5: |
mptapton | 0:6b0b61d411ad | 105 | note = 330; |
mptapton | 0:6b0b61d411ad | 106 | key= "E4"; |
mptapton | 0:6b0b61d411ad | 107 | break; |
mptapton | 0:6b0b61d411ad | 108 | } |
mptapton | 0:6b0b61d411ad | 109 | |
mptapton | 0:6b0b61d411ad | 110 | //Prepare for burst mode on all ADC pins and set up interrupt handler (using ADC library from Simon Blandford |
mptapton | 0:6b0b61d411ad | 111 | adc.append(sample_audio); |
mptapton | 0:6b0b61d411ad | 112 | adc.startmode(0,0); |
mptapton | 0:6b0b61d411ad | 113 | adc.burst(1); |
mptapton | 0:6b0b61d411ad | 114 | adc.setup(p20,1); |
mptapton | 0:6b0b61d411ad | 115 | |
mptapton | 0:6b0b61d411ad | 116 | //start the interrupt and wait for about 4096 samples |
mptapton | 0:6b0b61d411ad | 117 | adc.interrupt_state(p20,1); |
mptapton | 0:6b0b61d411ad | 118 | wait(.2); |
mptapton | 0:6b0b61d411ad | 119 | |
mptapton | 0:6b0b61d411ad | 120 | //Finsh up - Unset pin 20 |
mptapton | 0:6b0b61d411ad | 121 | adc.interrupt_state(p20,0); |
mptapton | 0:6b0b61d411ad | 122 | adc.setup(p20,0); |
mptapton | 0:6b0b61d411ad | 123 | int actual_rate = adc.actual_sample_rate(); |
mptapton | 0:6b0b61d411ad | 124 | |
mptapton | 0:6b0b61d411ad | 125 | //for debugging tell the terminal sample rate and how many samples we took |
mptapton | 0:6b0b61d411ad | 126 | printf("Requested max sample rate is %u, actual max sample rate is %u.\n", |
mptapton | 0:6b0b61d411ad | 127 | SAMPLE_RATE, actual_rate); |
mptapton | 0:6b0b61d411ad | 128 | printf("We did %i samples\n",Counter); |
mptapton | 0:6b0b61d411ad | 129 | |
mptapton | 0:6b0b61d411ad | 130 | high = 0; |
mptapton | 0:6b0b61d411ad | 131 | low = 0; |
mptapton | 0:6b0b61d411ad | 132 | for (int i=3; i<46; i+=3) { |
mptapton | 0:6b0b61d411ad | 133 | high1 = goertzelFilter(Buffer, (note + i ), Counter); |
mptapton | 0:6b0b61d411ad | 134 | if (high1 > high) high=high1; |
mptapton | 0:6b0b61d411ad | 135 | } |
mptapton | 0:6b0b61d411ad | 136 | for (int i=3; i<46; i+=3) { |
mptapton | 0:6b0b61d411ad | 137 | low1 = goertzelFilter(Buffer, (note - i ), Counter); |
mptapton | 0:6b0b61d411ad | 138 | if (low1 > low) low=low1; |
mptapton | 0:6b0b61d411ad | 139 | } |
mptapton | 0:6b0b61d411ad | 140 | in_tune1 = goertzelFilter(Buffer, (note+1), Counter); |
mptapton | 0:6b0b61d411ad | 141 | in_tune2 = goertzelFilter(Buffer, note, Counter); |
mptapton | 0:6b0b61d411ad | 142 | in_tune3 = goertzelFilter(Buffer, (note-1), Counter); |
mptapton | 0:6b0b61d411ad | 143 | |
mptapton | 0:6b0b61d411ad | 144 | if ((in_tune1 > in_tune2) && (in_tune1 > in_tune3)) in_tune = in_tune1; |
mptapton | 0:6b0b61d411ad | 145 | else if ((in_tune2 > in_tune1) && (in_tune2 > in_tune3)) in_tune = in_tune2; |
mptapton | 0:6b0b61d411ad | 146 | else in_tune = in_tune3; |
mptapton | 0:6b0b61d411ad | 147 | |
mptapton | 0:6b0b61d411ad | 148 | if ((in_tune > high) && (in_tune > low)) { |
mptapton | 0:6b0b61d411ad | 149 | led_high = 0; |
mptapton | 0:6b0b61d411ad | 150 | led_ok = 1; |
mptapton | 0:6b0b61d411ad | 151 | led_low = 0; |
mptapton | 0:6b0b61d411ad | 152 | } else if (high > in_tune) { |
mptapton | 0:6b0b61d411ad | 153 | led_high = 1; |
mptapton | 0:6b0b61d411ad | 154 | led_ok = 0; |
mptapton | 0:6b0b61d411ad | 155 | led_low = 0; |
mptapton | 0:6b0b61d411ad | 156 | } else if (low > in_tune) { |
mptapton | 0:6b0b61d411ad | 157 | led_high = 0; |
mptapton | 0:6b0b61d411ad | 158 | led_ok = 0; |
mptapton | 0:6b0b61d411ad | 159 | led_low = 1; |
mptapton | 0:6b0b61d411ad | 160 | } else { |
mptapton | 0:6b0b61d411ad | 161 | led_high = 0; |
mptapton | 0:6b0b61d411ad | 162 | led_ok = 0; |
mptapton | 0:6b0b61d411ad | 163 | led_low = 0; |
mptapton | 0:6b0b61d411ad | 164 | } |
mptapton | 0:6b0b61d411ad | 165 | |
mptapton | 0:6b0b61d411ad | 166 | int pintwenty = adc.read(p20); //read pin 20 |
mptapton | 0:6b0b61d411ad | 167 | lcd.locate(0,1); |
mptapton | 0:6b0b61d411ad | 168 | lcd.printf("%s %iHz %d\n",key, (int) note, pintwenty); |
mptapton | 1:c8ec50d75f80 | 169 | if (led_ok) { |
mptapton | 1:c8ec50d75f80 | 170 | lcd.printf("Tuner- In Tune"); |
mptapton | 1:c8ec50d75f80 | 171 | device.printf("QT%sN2Z", key);// send to mbed 2 |
mptapton | 1:c8ec50d75f80 | 172 | } |
mptapton | 1:c8ec50d75f80 | 173 | else if (led_low) { |
mptapton | 1:c8ec50d75f80 | 174 | lcd.printf("Tuner- 2Low "); |
mptapton | 1:c8ec50d75f80 | 175 | device.printf("QT%sN3Z", key);// send to mbed 2 |
mptapton | 1:c8ec50d75f80 | 176 | } |
mptapton | 1:c8ec50d75f80 | 177 | else if (led_high){ |
mptapton | 1:c8ec50d75f80 | 178 | lcd.printf("Tuner- 2High "); |
mptapton | 1:c8ec50d75f80 | 179 | device.printf("QT%sN1Z", key);// send to mbed 2 |
mptapton | 1:c8ec50d75f80 | 180 | } |
mptapton | 1:c8ec50d75f80 | 181 | Counter = 0; |
mptapton | 0:6b0b61d411ad | 182 | } //inner while (1)loop |
mptapton | 0:6b0b61d411ad | 183 | } else { //if myinputpin |
mptapton | 0:6b0b61d411ad | 184 | |
mptapton | 0:6b0b61d411ad | 185 | lcd.cls (); //Chord Tutor Section based on p21 being 0v |
mptapton | 0:6b0b61d411ad | 186 | |
mptapton | 0:6b0b61d411ad | 187 | //Interupt for Switching chord selection |
mptapton | 0:6b0b61d411ad | 188 | button1.mode(PullDown); |
mptapton | 0:6b0b61d411ad | 189 | button1.rise(&button1_pressed); |
mptapton | 0:6b0b61d411ad | 190 | |
mptapton | 0:6b0b61d411ad | 191 | |
mptapton | 0:6b0b61d411ad | 192 | |
mptapton | 0:6b0b61d411ad | 193 | while (1) { |
mptapton | 0:6b0b61d411ad | 194 | |
mptapton | 0:6b0b61d411ad | 195 | switch (chord_select) { |
mptapton | 0:6b0b61d411ad | 196 | case 0: |
mptapton | 0:6b0b61d411ad | 197 | note = 82; |
mptapton | 0:6b0b61d411ad | 198 | key= "E2"; |
mptapton | 0:6b0b61d411ad | 199 | //send E chord white LED pattern |
mptapton | 0:6b0b61d411ad | 200 | break; |
mptapton | 0:6b0b61d411ad | 201 | case 1: |
mptapton | 0:6b0b61d411ad | 202 | note = 110; |
mptapton | 0:6b0b61d411ad | 203 | key= "A2"; |
mptapton | 0:6b0b61d411ad | 204 | //send A chord white LED pattern |
mptapton | 0:6b0b61d411ad | 205 | break; |
mptapton | 0:6b0b61d411ad | 206 | case 2: |
mptapton | 0:6b0b61d411ad | 207 | note = 147; |
mptapton | 0:6b0b61d411ad | 208 | key= "D3"; |
mptapton | 0:6b0b61d411ad | 209 | //send D chord white LED pattern |
mptapton | 0:6b0b61d411ad | 210 | break; |
mptapton | 0:6b0b61d411ad | 211 | case 3: |
mptapton | 0:6b0b61d411ad | 212 | note = 196; |
mptapton | 0:6b0b61d411ad | 213 | key= "G3"; |
mptapton | 0:6b0b61d411ad | 214 | //send G chord white LED pattern |
mptapton | 0:6b0b61d411ad | 215 | break; |
mptapton | 0:6b0b61d411ad | 216 | case 4: |
mptapton | 0:6b0b61d411ad | 217 | note = 247; |
mptapton | 0:6b0b61d411ad | 218 | key= "B3"; |
mptapton | 0:6b0b61d411ad | 219 | //send B chord white LED pattern |
mptapton | 0:6b0b61d411ad | 220 | break; |
mptapton | 0:6b0b61d411ad | 221 | case 5: |
mptapton | 0:6b0b61d411ad | 222 | note = 2349; |
mptapton | 0:6b0b61d411ad | 223 | key= "D7"; |
mptapton | 0:6b0b61d411ad | 224 | //send D7 chord white LED pattern |
mptapton | 0:6b0b61d411ad | 225 | break; |
mptapton | 0:6b0b61d411ad | 226 | case 6: |
mptapton | 0:6b0b61d411ad | 227 | note = 131; |
mptapton | 0:6b0b61d411ad | 228 | key= "C3"; |
mptapton | 0:6b0b61d411ad | 229 | //send C chord white LED pattern |
mptapton | 0:6b0b61d411ad | 230 | break; |
mptapton | 0:6b0b61d411ad | 231 | case 7: |
mptapton | 0:6b0b61d411ad | 232 | note = 174; |
mptapton | 0:6b0b61d411ad | 233 | key= "F3"; |
mptapton | 0:6b0b61d411ad | 234 | //send F chord white LED pattern |
mptapton | 0:6b0b61d411ad | 235 | break; |
mptapton | 0:6b0b61d411ad | 236 | case 8: |
mptapton | 0:6b0b61d411ad | 237 | note = 65; |
mptapton | 0:6b0b61d411ad | 238 | key= "C2"; |
mptapton | 0:6b0b61d411ad | 239 | //send C chord white LED pattern |
mptapton | 0:6b0b61d411ad | 240 | break; |
mptapton | 0:6b0b61d411ad | 241 | case 9: |
mptapton | 0:6b0b61d411ad | 242 | note = 87; |
mptapton | 0:6b0b61d411ad | 243 | key= "F2"; |
mptapton | 0:6b0b61d411ad | 244 | //send F chord white LED pattern |
mptapton | 0:6b0b61d411ad | 245 | break; |
mptapton | 0:6b0b61d411ad | 246 | } |
mptapton | 0:6b0b61d411ad | 247 | |
mptapton | 0:6b0b61d411ad | 248 | //Prepare for burst mode on all ADC pins and set up interrupt handler (using ADC library from Simon Blandford |
mptapton | 0:6b0b61d411ad | 249 | adc.append(sample_audio); |
mptapton | 0:6b0b61d411ad | 250 | adc.startmode(0,0); |
mptapton | 0:6b0b61d411ad | 251 | adc.burst(1); |
mptapton | 0:6b0b61d411ad | 252 | adc.setup(p20,1); |
mptapton | 0:6b0b61d411ad | 253 | |
mptapton | 0:6b0b61d411ad | 254 | //start the interrupt and wait for about 4096 samples |
mptapton | 0:6b0b61d411ad | 255 | adc.interrupt_state(p20,1); |
mptapton | 0:6b0b61d411ad | 256 | wait(.2); |
mptapton | 0:6b0b61d411ad | 257 | |
mptapton | 0:6b0b61d411ad | 258 | //Finsh up - Unset pin 20 |
mptapton | 0:6b0b61d411ad | 259 | adc.interrupt_state(p20,0); |
mptapton | 0:6b0b61d411ad | 260 | adc.setup(p20,0); |
mptapton | 0:6b0b61d411ad | 261 | int actual_rate = adc.actual_sample_rate(); |
mptapton | 0:6b0b61d411ad | 262 | |
mptapton | 0:6b0b61d411ad | 263 | //for debugging tell the terminal sample rate and how many samples we took |
mptapton | 0:6b0b61d411ad | 264 | printf("Requested max sample rate is %u, actual max sample rate is %u.\n", |
mptapton | 0:6b0b61d411ad | 265 | SAMPLE_RATE, actual_rate); |
mptapton | 0:6b0b61d411ad | 266 | printf("We did %i samples\n",Counter); |
mptapton | 0:6b0b61d411ad | 267 | |
mptapton | 0:6b0b61d411ad | 268 | high = 0; |
mptapton | 0:6b0b61d411ad | 269 | low = 0; |
mptapton | 0:6b0b61d411ad | 270 | for (int i=3; i<46; i+=3) { |
mptapton | 0:6b0b61d411ad | 271 | high1 = goertzelFilter(Buffer, (note + i ), Counter); |
mptapton | 0:6b0b61d411ad | 272 | if (high1 > high) high=high1; |
mptapton | 0:6b0b61d411ad | 273 | } |
mptapton | 0:6b0b61d411ad | 274 | for (int i=3; i<46; i+=3) { |
mptapton | 0:6b0b61d411ad | 275 | low1 = goertzelFilter(Buffer, (note - i ), Counter); |
mptapton | 0:6b0b61d411ad | 276 | if (low1 > low) low=low1; |
mptapton | 0:6b0b61d411ad | 277 | } |
mptapton | 0:6b0b61d411ad | 278 | in_tune1 = goertzelFilter(Buffer, (note+1), Counter); |
mptapton | 0:6b0b61d411ad | 279 | in_tune2 = goertzelFilter(Buffer, note, Counter); |
mptapton | 0:6b0b61d411ad | 280 | in_tune3 = goertzelFilter(Buffer, (note-1), Counter); |
mptapton | 0:6b0b61d411ad | 281 | |
mptapton | 0:6b0b61d411ad | 282 | if ((in_tune1 > in_tune2) && (in_tune1 > in_tune3)) in_tune = in_tune1; |
mptapton | 0:6b0b61d411ad | 283 | else if ((in_tune2 > in_tune1) && (in_tune2 > in_tune3)) in_tune = in_tune2; |
mptapton | 0:6b0b61d411ad | 284 | else in_tune = in_tune3; |
mptapton | 0:6b0b61d411ad | 285 | if ((in_tune > high) && (in_tune > low)) { |
mptapton | 0:6b0b61d411ad | 286 | led_high = 0; |
mptapton | 0:6b0b61d411ad | 287 | led_ok = 1; |
mptapton | 0:6b0b61d411ad | 288 | led_low = 0; |
mptapton | 0:6b0b61d411ad | 289 | } else if (high > in_tune) { |
mptapton | 0:6b0b61d411ad | 290 | led_high = 1; |
mptapton | 0:6b0b61d411ad | 291 | led_ok = 0; |
mptapton | 0:6b0b61d411ad | 292 | led_low = 0; |
mptapton | 0:6b0b61d411ad | 293 | } else if (low > in_tune) { |
mptapton | 0:6b0b61d411ad | 294 | led_high = 0; |
mptapton | 0:6b0b61d411ad | 295 | led_ok = 0; |
mptapton | 0:6b0b61d411ad | 296 | led_low = 1; |
mptapton | 0:6b0b61d411ad | 297 | } else { |
mptapton | 0:6b0b61d411ad | 298 | led_high = 0; |
mptapton | 0:6b0b61d411ad | 299 | led_ok = 0; |
mptapton | 0:6b0b61d411ad | 300 | led_low = 0; |
mptapton | 0:6b0b61d411ad | 301 | } |
mptapton | 0:6b0b61d411ad | 302 | |
mptapton | 0:6b0b61d411ad | 303 | int pintwenty = adc.read(p20); //read pin 20 |
mptapton | 0:6b0b61d411ad | 304 | lcd.locate(0,1); |
mptapton | 0:6b0b61d411ad | 305 | lcd.printf("%s ",key); |
mptapton | 0:6b0b61d411ad | 306 | lcd.locate(4,1);// need to deal with lcd screen changes to length of frequencies |
mptapton | 0:6b0b61d411ad | 307 | lcd.printf(" "); |
mptapton | 0:6b0b61d411ad | 308 | lcd.locate(4,1); |
mptapton | 0:6b0b61d411ad | 309 | lcd.printf("%iHz",(int) note); |
mptapton | 0:6b0b61d411ad | 310 | lcd.locate(11,1); |
mptapton | 0:6b0b61d411ad | 311 | lcd.printf("%4d\n",pintwenty); //need to deal with lcd screen changes to restrict input decimal range to 4sf |
mptapton | 1:c8ec50d75f80 | 312 | if (led_ok) { |
mptapton | 1:c8ec50d75f80 | 313 | lcd.printf("Play %s->In Tune",key); |
mptapton | 1:c8ec50d75f80 | 314 | device.printf("QV%sN2Z", key);// send to mbed 2 |
mptapton | 1:c8ec50d75f80 | 315 | } |
mptapton | 1:c8ec50d75f80 | 316 | else if (led_low) { |
mptapton | 1:c8ec50d75f80 | 317 | lcd.printf("Play %s -> 2Low ",key); |
mptapton | 1:c8ec50d75f80 | 318 | device.printf("QV%sN3Z", key);// send to mbed 2 |
mptapton | 1:c8ec50d75f80 | 319 | } |
mptapton | 1:c8ec50d75f80 | 320 | else if (led_high) { |
mptapton | 1:c8ec50d75f80 | 321 | lcd.printf("Play %s -> 2High",key); |
mptapton | 1:c8ec50d75f80 | 322 | device.printf("QV%sN1Z", key);// send to mbed 2 |
mptapton | 1:c8ec50d75f80 | 323 | } |
mptapton | 1:c8ec50d75f80 | 324 | Counter = 0; |
mptapton | 0:6b0b61d411ad | 325 | } |
mptapton | 0:6b0b61d411ad | 326 | } |
mptapton | 0:6b0b61d411ad | 327 | |
mptapton | 0:6b0b61d411ad | 328 | |
mptapton | 0:6b0b61d411ad | 329 | } |
mptapton | 0:6b0b61d411ad | 330 | } |