Solo project mbed 2

Dependencies:   PololuLedStrip mbed

Fork of SX10_BigBangFinal_A by Tapton Eesarm

Committer:
mptapton
Date:
Mon Feb 06 09:42:24 2017 +0000
Revision:
2:bc7345c92188
Parent:
1:e4d11295b3f4
Tapton School project guitar tuner mbed2 code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
taptoneesarm 0:5ddd4b0f64f8 1 #include "mbed.h"
taptoneesarm 0:5ddd4b0f64f8 2 #include "PololuLedStrip.h"
taptoneesarm 0:5ddd4b0f64f8 3 #include <iostream>
taptoneesarm 0:5ddd4b0f64f8 4
mptapton 2:bc7345c92188 5 #define LED_COUNT 36 //was 60
taptoneesarm 0:5ddd4b0f64f8 6
taptoneesarm 0:5ddd4b0f64f8 7 Serial pc(USBTX, USBRX); // tx, rx
mptapton 1:e4d11295b3f4 8 Serial device(p13, p14); // tx, rx to connect to mbed 1
mptapton 1:e4d11295b3f4 9
mptapton 2:bc7345c92188 10 DigitalIn intune(p19);
mptapton 2:bc7345c92188 11 DigitalIn toohigh(p18);
mptapton 2:bc7345c92188 12 DigitalIn toolow(p17);
mptapton 2:bc7345c92188 13 DigitalIn state(p16);
mptapton 1:e4d11295b3f4 14 DigitalOut ledd1(LED1);
mptapton 1:e4d11295b3f4 15 DigitalOut ledd2(LED2);
mptapton 1:e4d11295b3f4 16 DigitalOut ledd3(LED3);
mptapton 1:e4d11295b3f4 17 DigitalOut ledd4(LED4);
mptapton 2:bc7345c92188 18 DigitalIn myInputPin (p21); //select tuner or chord learning mode
mptapton 1:e4d11295b3f4 19
mptapton 2:bc7345c92188 20 char typed[20];
taptoneesarm 0:5ddd4b0f64f8 21
taptoneesarm 0:5ddd4b0f64f8 22 PololuLedStrip ledStrip(p11);
taptoneesarm 0:5ddd4b0f64f8 23
taptoneesarm 0:5ddd4b0f64f8 24 rgb_color colors[LED_COUNT];
taptoneesarm 0:5ddd4b0f64f8 25
taptoneesarm 0:5ddd4b0f64f8 26 Timer timer;
taptoneesarm 0:5ddd4b0f64f8 27
mptapton 2:bc7345c92188 28 int aMajor[6] = {0,2,2,2,0,-1}; //<<<< CHORDS supported in Chord Mode for LED Strip
taptoneesarm 0:5ddd4b0f64f8 29 int bMajor[6] = {2,4,4,4,2,-1};
taptoneesarm 0:5ddd4b0f64f8 30 int cMajor[6] = {0,1,0,2,3,-1};
taptoneesarm 0:5ddd4b0f64f8 31 int dMajor[6] = {2,3,2,0,-1,-1};
taptoneesarm 0:5ddd4b0f64f8 32 int eMajor[6] = {0,0,1,2,2,0};
taptoneesarm 0:5ddd4b0f64f8 33 int fMajor[6] = {1,-1,2,3,3,1};
taptoneesarm 0:5ddd4b0f64f8 34 int gMajor[6] = {3,0,0,0,2,3};
taptoneesarm 0:5ddd4b0f64f8 35
mptapton 2:bc7345c92188 36 int lowEstring[6] = {0,11,12,23,24,35}; //<<<< STRINGS supported in Tuner mode for LED strip
mptapton 2:bc7345c92188 37 int Astring[6] = {1,10,13,22,25,34};
mptapton 2:bc7345c92188 38 int Dstring[6] = {2,9,14,21,26,33};
mptapton 2:bc7345c92188 39 int Gstring[6] = {3,8,15,20,27,32};
mptapton 2:bc7345c92188 40 int Bstring[6] = {4,7,16,19,28,31};
mptapton 2:bc7345c92188 41 int HiEstring[6] = {5,6,17,18,29,30};
taptoneesarm 0:5ddd4b0f64f8 42 /*
taptoneesarm 0:5ddd4b0f64f8 43 Above are the various arrays which represent the location of the string
taptoneesarm 0:5ddd4b0f64f8 44 played in a given fret to achieve a certain chord. The layout
taptoneesarm 0:5ddd4b0f64f8 45 of this arrangement helps the mBed light up the correct pattern
taptoneesarm 0:5ddd4b0f64f8 46 of LEDs on the LED strip. Not all of the chords can be played as the
taptoneesarm 0:5ddd4b0f64f8 47 Solo only includes the first six frets.
taptoneesarm 0:5ddd4b0f64f8 48 */
taptoneesarm 0:5ddd4b0f64f8 49
taptoneesarm 0:5ddd4b0f64f8 50 int chordCode = 0;
taptoneesarm 0:5ddd4b0f64f8 51 int testResult = 0;
taptoneesarm 0:5ddd4b0f64f8 52 int interpretedChordCode = 0;
taptoneesarm 0:5ddd4b0f64f8 53
taptoneesarm 0:5ddd4b0f64f8 54 using namespace std;
taptoneesarm 0:5ddd4b0f64f8 55
taptoneesarm 0:5ddd4b0f64f8 56 int ledMapping(int fret, int str)
taptoneesarm 0:5ddd4b0f64f8 57 {
taptoneesarm 0:5ddd4b0f64f8 58 int result;
taptoneesarm 0:5ddd4b0f64f8 59 // Initialise a variable that represents the specific number of the LED
taptoneesarm 0:5ddd4b0f64f8 60 // that is to be lit up
taptoneesarm 0:5ddd4b0f64f8 61 if(fret != -1)
taptoneesarm 0:5ddd4b0f64f8 62 {
taptoneesarm 0:5ddd4b0f64f8 63 if(fret%2 != 0)
taptoneesarm 0:5ddd4b0f64f8 64 // If the fret number is odd...
taptoneesarm 0:5ddd4b0f64f8 65 {
taptoneesarm 0:5ddd4b0f64f8 66 result = 6*fret + str - 1;
taptoneesarm 0:5ddd4b0f64f8 67 // ...then the LED number for that fret corresponds to the above formula
taptoneesarm 0:5ddd4b0f64f8 68 } else
taptoneesarm 0:5ddd4b0f64f8 69 // Otherwise if the fret number is even...
taptoneesarm 0:5ddd4b0f64f8 70 {
taptoneesarm 0:5ddd4b0f64f8 71 result = 6*(fret + 1) - str;
taptoneesarm 0:5ddd4b0f64f8 72 // ...then the LED number for that fret corresponds to the above formula
taptoneesarm 0:5ddd4b0f64f8 73 }
taptoneesarm 0:5ddd4b0f64f8 74 return result;
taptoneesarm 0:5ddd4b0f64f8 75 }
taptoneesarm 0:5ddd4b0f64f8 76 return -1;
taptoneesarm 0:5ddd4b0f64f8 77 // Output the LED number as a return value so that other parts of the code can
taptoneesarm 0:5ddd4b0f64f8 78 // use it when this function is called for a specific chord.
taptoneesarm 0:5ddd4b0f64f8 79 }
taptoneesarm 0:5ddd4b0f64f8 80
taptoneesarm 0:5ddd4b0f64f8 81 /*
taptoneesarm 0:5ddd4b0f64f8 82 * The decoder takes a char value that represents a chord, whether it is sharp or natural and whether
taptoneesarm 0:5ddd4b0f64f8 83 * it is major or minor. The inputted value for chord is either a capital (major) or lowercase letter (minor).
taptoneesarm 0:5ddd4b0f64f8 84 * Also assigned is a sharp value (either 0 or 1, where 0 is a natural note and 1 is a sharp)
taptoneesarm 0:5ddd4b0f64f8 85 */
taptoneesarm 0:5ddd4b0f64f8 86
taptoneesarm 0:5ddd4b0f64f8 87 int decoder(string typed)
taptoneesarm 0:5ddd4b0f64f8 88 {
mptapton 2:bc7345c92188 89 int ascii = int(typed[0]);// get the hex value for input char from mbed1
mptapton 2:bc7345c92188 90 int chordValue; //set up integer 0-6 to represent A-G for later
mptapton 2:bc7345c92188 91 if (65 <= ascii && ascii <= 71) //test if mbed1 input is a major chord A-G
mptapton 2:bc7345c92188 92 {
mptapton 2:bc7345c92188 93 chordValue = ascii - 65; // it is A-G so set int to appropriate 0-6
mptapton 2:bc7345c92188 94 // pc.printf(" %d ", chordValue);
mptapton 2:bc7345c92188 95 /*
mptapton 2:bc7345c92188 96 switch (chordValue) { //for diagnostics use putc not printf to send
mptapton 2:bc7345c92188 97 case 0: //received char from mbed1 to mbed2's usb pc
mptapton 2:bc7345c92188 98 pc.putc('A');
mptapton 2:bc7345c92188 99 break;
mptapton 2:bc7345c92188 100 case 1:
mptapton 2:bc7345c92188 101 pc.putc('B');
mptapton 2:bc7345c92188 102 break;
mptapton 2:bc7345c92188 103 case 2:
mptapton 2:bc7345c92188 104 pc.putc('C');
mptapton 2:bc7345c92188 105 break;
mptapton 2:bc7345c92188 106 case 3:
mptapton 2:bc7345c92188 107 pc.putc('D');
mptapton 2:bc7345c92188 108 break;
mptapton 2:bc7345c92188 109 case 4:
mptapton 2:bc7345c92188 110 pc.putc('E');
mptapton 2:bc7345c92188 111 break;
mptapton 2:bc7345c92188 112 case 5:
mptapton 2:bc7345c92188 113 pc.putc('F');
mptapton 2:bc7345c92188 114 break;
mptapton 2:bc7345c92188 115 case 6:
mptapton 2:bc7345c92188 116 pc.putc('G');
mptapton 2:bc7345c92188 117 break;
mptapton 2:bc7345c92188 118 }
mptapton 2:bc7345c92188 119 */
mptapton 2:bc7345c92188 120 }
mptapton 2:bc7345c92188 121 return chordValue;
taptoneesarm 0:5ddd4b0f64f8 122 }
taptoneesarm 0:5ddd4b0f64f8 123
mptapton 2:bc7345c92188 124
taptoneesarm 0:5ddd4b0f64f8 125 void illuminator (int position, int colour)
taptoneesarm 0:5ddd4b0f64f8 126 {
taptoneesarm 0:5ddd4b0f64f8 127 //pc.printf ("Position: %d Colour: %d\n",position,colour);
taptoneesarm 0:5ddd4b0f64f8 128 if (position != -1)
taptoneesarm 0:5ddd4b0f64f8 129 {
mptapton 1:e4d11295b3f4 130 if (colour == -1) //out of tune
taptoneesarm 0:5ddd4b0f64f8 131 {
taptoneesarm 0:5ddd4b0f64f8 132 colors[position] = (rgb_color){40,0,0};
taptoneesarm 0:5ddd4b0f64f8 133 }
mptapton 1:e4d11295b3f4 134 else if (colour == 0) // processing
taptoneesarm 0:5ddd4b0f64f8 135 {
taptoneesarm 0:5ddd4b0f64f8 136 colors[position] = (rgb_color){40,40,40};
taptoneesarm 0:5ddd4b0f64f8 137 }
mptapton 1:e4d11295b3f4 138 else if (colour == 1) //in tune
taptoneesarm 0:5ddd4b0f64f8 139 {
taptoneesarm 0:5ddd4b0f64f8 140 colors[position] = (rgb_color){0,40,0};
taptoneesarm 0:5ddd4b0f64f8 141 }
taptoneesarm 0:5ddd4b0f64f8 142 else
taptoneesarm 0:5ddd4b0f64f8 143 {
taptoneesarm 0:5ddd4b0f64f8 144 pc.printf ("Error: invalid colour number in illuminator\n");
taptoneesarm 0:5ddd4b0f64f8 145 }
taptoneesarm 0:5ddd4b0f64f8 146 }
taptoneesarm 0:5ddd4b0f64f8 147 }
taptoneesarm 0:5ddd4b0f64f8 148
mptapton 2:bc7345c92188 149
mptapton 2:bc7345c92188 150 //Possible to change to a case/switch structure improve speed?
mptapton 2:bc7345c92188 151 int shaper (int shape, int colour)// <<<<<< CHORD SHAPER >>>>>>>
mptapton 2:bc7345c92188 152 {
mptapton 2:bc7345c92188 153 if (shape == 0)
mptapton 2:bc7345c92188 154 {
mptapton 2:bc7345c92188 155 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 156 {
mptapton 2:bc7345c92188 157 illuminator (ledMapping(aMajor[i],i+1), colour);
mptapton 2:bc7345c92188 158 }
mptapton 2:bc7345c92188 159 // feedback(colour);
mptapton 2:bc7345c92188 160 }
mptapton 2:bc7345c92188 161 else if (shape == 1)
mptapton 2:bc7345c92188 162 {
mptapton 2:bc7345c92188 163 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 164 {
mptapton 2:bc7345c92188 165 illuminator (ledMapping(bMajor[i],i+1), colour);
mptapton 2:bc7345c92188 166 }
mptapton 2:bc7345c92188 167 // feedback(colour);
mptapton 2:bc7345c92188 168
mptapton 2:bc7345c92188 169 }
mptapton 2:bc7345c92188 170 else if (shape == 2)
mptapton 2:bc7345c92188 171 {
mptapton 2:bc7345c92188 172 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 173 {
mptapton 2:bc7345c92188 174 illuminator (ledMapping(cMajor[i],i+1), colour);
mptapton 2:bc7345c92188 175 }
mptapton 2:bc7345c92188 176 // feedback(colour);
mptapton 2:bc7345c92188 177 }
mptapton 2:bc7345c92188 178 else if (shape == 3)
mptapton 2:bc7345c92188 179 {
mptapton 2:bc7345c92188 180 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 181 {
mptapton 2:bc7345c92188 182 illuminator (ledMapping(dMajor[i],i+1), colour);
mptapton 2:bc7345c92188 183 }
mptapton 2:bc7345c92188 184 // feedback(colour);
mptapton 2:bc7345c92188 185 }
mptapton 2:bc7345c92188 186 else if (shape == 4)
mptapton 2:bc7345c92188 187 {
mptapton 2:bc7345c92188 188 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 189 {
mptapton 2:bc7345c92188 190 illuminator (ledMapping(eMajor[i],i+1), colour);
mptapton 2:bc7345c92188 191 }
mptapton 2:bc7345c92188 192 // feedback(colour);
mptapton 2:bc7345c92188 193 }
mptapton 2:bc7345c92188 194 else if (shape == 5)
mptapton 2:bc7345c92188 195 {
mptapton 2:bc7345c92188 196 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 197 {
mptapton 2:bc7345c92188 198 illuminator (ledMapping(fMajor[i],i+1), colour);
mptapton 2:bc7345c92188 199 }
mptapton 2:bc7345c92188 200 // feedback(colour);
mptapton 2:bc7345c92188 201 }
mptapton 2:bc7345c92188 202 else if (shape == 6)
mptapton 2:bc7345c92188 203 {
mptapton 2:bc7345c92188 204 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 205 {
mptapton 2:bc7345c92188 206 illuminator (ledMapping(gMajor[i],i+1), colour);
mptapton 2:bc7345c92188 207 }
mptapton 2:bc7345c92188 208 // feedback(colour);
mptapton 2:bc7345c92188 209 }
taptoneesarm 0:5ddd4b0f64f8 210
mptapton 2:bc7345c92188 211 // Send the colors to the LED strip.
mptapton 2:bc7345c92188 212 // ledStrip.write(colors, LED_COUNT);
mptapton 2:bc7345c92188 213 return (0);
taptoneesarm 0:5ddd4b0f64f8 214 }
taptoneesarm 0:5ddd4b0f64f8 215
mptapton 2:bc7345c92188 216 //Possible to change to a case/switch structure improve speed?
mptapton 2:bc7345c92188 217 int Tunershaper (int shape, int colour) // <<<<<<<< TUNER SHAPER >>>>>>>>>
mptapton 2:bc7345c92188 218 {
mptapton 2:bc7345c92188 219 if (shape == 0)
mptapton 2:bc7345c92188 220 {
mptapton 2:bc7345c92188 221 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 222 {
mptapton 2:bc7345c92188 223 illuminator (lowEstring[i], colour);
mptapton 2:bc7345c92188 224 }
mptapton 2:bc7345c92188 225 // feedback(colour);
mptapton 2:bc7345c92188 226 }
mptapton 2:bc7345c92188 227 else if (shape == 1)
mptapton 2:bc7345c92188 228 {
mptapton 2:bc7345c92188 229 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 230 {
mptapton 2:bc7345c92188 231 illuminator (Astring[i], colour);
mptapton 2:bc7345c92188 232 }
mptapton 2:bc7345c92188 233 // feedback(colour);
mptapton 2:bc7345c92188 234
mptapton 2:bc7345c92188 235 }
mptapton 2:bc7345c92188 236 else if (shape == 2)
mptapton 2:bc7345c92188 237 {
mptapton 2:bc7345c92188 238 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 239 {
mptapton 2:bc7345c92188 240 illuminator (Dstring[i], colour);
mptapton 2:bc7345c92188 241 }
mptapton 2:bc7345c92188 242 // feedback(colour);
mptapton 2:bc7345c92188 243 }
mptapton 2:bc7345c92188 244 else if (shape == 3)
mptapton 2:bc7345c92188 245 {
mptapton 2:bc7345c92188 246 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 247 {
mptapton 2:bc7345c92188 248 illuminator (Gstring[i], colour);
mptapton 2:bc7345c92188 249 }
mptapton 2:bc7345c92188 250 // feedback(colour);
mptapton 2:bc7345c92188 251 }
mptapton 2:bc7345c92188 252 else if (shape == 4)
mptapton 2:bc7345c92188 253 {
mptapton 2:bc7345c92188 254 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 255 {
mptapton 2:bc7345c92188 256 illuminator (Bstring[i], colour);
mptapton 2:bc7345c92188 257 }
mptapton 2:bc7345c92188 258 // feedback(colour);
mptapton 2:bc7345c92188 259 }
mptapton 2:bc7345c92188 260 else if (shape == 5)
mptapton 2:bc7345c92188 261 {
mptapton 2:bc7345c92188 262 for(int i = 0; i<6; i++)
mptapton 2:bc7345c92188 263 {
mptapton 2:bc7345c92188 264 illuminator (HiEstring[i], colour);
mptapton 2:bc7345c92188 265 }
mptapton 2:bc7345c92188 266 // feedback(colour);
mptapton 2:bc7345c92188 267 }
taptoneesarm 0:5ddd4b0f64f8 268
mptapton 2:bc7345c92188 269 // Send the colors to the LED strip.
mptapton 2:bc7345c92188 270 //ledStrip.write(colors, LED_COUNT);
mptapton 2:bc7345c92188 271 return (0);
taptoneesarm 0:5ddd4b0f64f8 272 }
taptoneesarm 0:5ddd4b0f64f8 273
mptapton 2:bc7345c92188 274
mptapton 2:bc7345c92188 275 void clearLEDstrip() //writes to all the LEDs to clear them
mptapton 2:bc7345c92188 276 {
mptapton 2:bc7345c92188 277 wait(0.2);
mptapton 2:bc7345c92188 278 for(int i=0; i < LED_COUNT ; i++)
taptoneesarm 0:5ddd4b0f64f8 279 {
mptapton 2:bc7345c92188 280 colors[i] = (rgb_color){ 0, 0, 0 };
taptoneesarm 0:5ddd4b0f64f8 281 }
mptapton 2:bc7345c92188 282 ledStrip.write(colors, LED_COUNT);
mptapton 2:bc7345c92188 283 }
taptoneesarm 0:5ddd4b0f64f8 284
mptapton 2:bc7345c92188 285 void callback() //interrupt from serial port from mbed1
mptapton 2:bc7345c92188 286 {
mptapton 2:bc7345c92188 287 ledd1=1; // received character from mbed1
mptapton 2:bc7345c92188 288 typed[0]=device.getc(); //get char from mbed1 via serial port
mptapton 2:bc7345c92188 289 }
taptoneesarm 0:5ddd4b0f64f8 290 int main()
taptoneesarm 0:5ddd4b0f64f8 291 {
mptapton 2:bc7345c92188 292 pc.baud (115200); //for pc usb
mptapton 1:e4d11295b3f4 293 device.baud(19200); //for communications with mbed 1
mptapton 2:bc7345c92188 294 myInputPin.mode(PullUp); //set the mbed to use a pullup resistor
taptoneesarm 0:5ddd4b0f64f8 295 string chord;
mptapton 2:bc7345c92188 296 int chordCode;
mptapton 2:bc7345c92188 297 setbuf(stdin, NULL);//clear the serial input buffer
mptapton 2:bc7345c92188 298 device.attach(&callback);// for serial interupt callback function
mptapton 2:bc7345c92188 299 clearLEDstrip();
mptapton 2:bc7345c92188 300
mptapton 2:bc7345c92188 301 myInputPin.mode(PullUp); //set the mbed to use a pullup resistor
mptapton 2:bc7345c92188 302 if (myInputPin) // <<<<SELECT GUITAR TUNER OR CHORD TRAINER FUNCTION>>>
taptoneesarm 0:5ddd4b0f64f8 303 {
mptapton 2:bc7345c92188 304 while(1)
mptapton 2:bc7345c92188 305 {
mptapton 2:bc7345c92188 306 ledd1=0; //received character from mbed1
mptapton 2:bc7345c92188 307 ledd2=toolow; //inputs from mbed1 mapped onto mbed 2 LED's
mptapton 2:bc7345c92188 308 ledd3=intune; //
mptapton 2:bc7345c92188 309 ledd4=toohigh;//
mptapton 2:bc7345c92188 310 // pc.putc(typed[0]); //debugging
mptapton 2:bc7345c92188 311 /* chordCode = decoder(typed); //takes input char from mbed1 and gives back 0-6 to represent chord selected A-G
mptapton 2:bc7345c92188 312 shaper(chordCode, 0); //light current chord in white (0)
mptapton 2:bc7345c92188 313 wait(0.8); //hold it for a period so user can see it
mptapton 2:bc7345c92188 314 if (intune) //read mbed1 intune pin and light the green LEDs
mptapton 2:bc7345c92188 315 {
mptapton 2:bc7345c92188 316 shaper(chordCode, 1); //green light (1)
mptapton 2:bc7345c92188 317 wait(0.4);
mptapton 2:bc7345c92188 318 }
mptapton 2:bc7345c92188 319 if ((toohigh) || (toolow))//read mbed1 toohigh and toolow pins and light the red LEDs
taptoneesarm 0:5ddd4b0f64f8 320 {
mptapton 2:bc7345c92188 321 shaper(chordCode, -1); //red light (-1)
mptapton 2:bc7345c92188 322 wait(0.4);
mptapton 2:bc7345c92188 323 } */
mptapton 2:bc7345c92188 324
mptapton 2:bc7345c92188 325 /* colors[0] = (rgb_color){0,40,0};
mptapton 2:bc7345c92188 326 colors[11] = (rgb_color){0,40,0};
mptapton 2:bc7345c92188 327 colors[12] = (rgb_color){0,40,0};
mptapton 2:bc7345c92188 328 colors[23] = (rgb_color){0,40,0};
mptapton 2:bc7345c92188 329 colors[24] = (rgb_color){0,40,0};
mptapton 2:bc7345c92188 330 colors[35] = (rgb_color){0,40,0};
mptapton 2:bc7345c92188 331 ledStrip.write(colors, LED_COUNT);
mptapton 2:bc7345c92188 332 */
mptapton 2:bc7345c92188 333
mptapton 2:bc7345c92188 334 for(int j = 0; j<6; j++)
mptapton 2:bc7345c92188 335 {
mptapton 2:bc7345c92188 336 chordCode=j;
mptapton 2:bc7345c92188 337 Tunershaper(chordCode, -1); //red
mptapton 2:bc7345c92188 338 wait(0.5);
mptapton 2:bc7345c92188 339 ledStrip.write(colors, LED_COUNT);
mptapton 2:bc7345c92188 340 }
mptapton 2:bc7345c92188 341 for(int j = 0; j<6; j++)
mptapton 2:bc7345c92188 342 {
mptapton 2:bc7345c92188 343 chordCode=j;
mptapton 2:bc7345c92188 344 Tunershaper(chordCode, 1); //green
mptapton 2:bc7345c92188 345 wait(0.5);
mptapton 2:bc7345c92188 346 ledStrip.write(colors, LED_COUNT);
mptapton 2:bc7345c92188 347 }
mptapton 2:bc7345c92188 348 for(int j = 0; j<6; j++)
mptapton 2:bc7345c92188 349 {
mptapton 2:bc7345c92188 350 chordCode=j;
mptapton 2:bc7345c92188 351 Tunershaper(chordCode, 0); //green
mptapton 2:bc7345c92188 352 wait(0.5);
mptapton 2:bc7345c92188 353 ledStrip.write(colors, LED_COUNT);
taptoneesarm 0:5ddd4b0f64f8 354 }
mptapton 2:bc7345c92188 355 /*
mptapton 2:bc7345c92188 356 chordCode=0;
mptapton 2:bc7345c92188 357 Tunershaper(chordCode, 0); //white
mptapton 2:bc7345c92188 358 wait(0.5);
mptapton 2:bc7345c92188 359 ledStrip.write(colors, LED_COUNT);
mptapton 2:bc7345c92188 360
mptapton 2:bc7345c92188 361 chordCode=1;
mptapton 2:bc7345c92188 362 Tunershaper(chordCode, 0); //white
mptapton 2:bc7345c92188 363 wait(0.5);
mptapton 2:bc7345c92188 364 ledStrip.write(colors, LED_COUNT);
mptapton 2:bc7345c92188 365
mptapton 2:bc7345c92188 366 chordCode=2;
mptapton 2:bc7345c92188 367 Tunershaper(chordCode, 0); //white
mptapton 2:bc7345c92188 368 wait(0.5);
mptapton 2:bc7345c92188 369 ledStrip.write(colors, LED_COUNT);
mptapton 2:bc7345c92188 370
mptapton 2:bc7345c92188 371 chordCode=3;
mptapton 2:bc7345c92188 372 Tunershaper(chordCode, 0); //white
mptapton 2:bc7345c92188 373 wait(0.5);
mptapton 2:bc7345c92188 374 ledStrip.write(colors, LED_COUNT);
mptapton 2:bc7345c92188 375
mptapton 2:bc7345c92188 376 chordCode=4;
mptapton 2:bc7345c92188 377 Tunershaper(chordCode, 0); //white
mptapton 2:bc7345c92188 378 wait(0.5);
mptapton 2:bc7345c92188 379 ledStrip.write(colors, LED_COUNT);
mptapton 2:bc7345c92188 380
mptapton 2:bc7345c92188 381 chordCode=5;
mptapton 2:bc7345c92188 382 Tunershaper(chordCode, 0); //white
mptapton 2:bc7345c92188 383 wait(0.5);
mptapton 2:bc7345c92188 384 ledStrip.write(colors, LED_COUNT);
mptapton 2:bc7345c92188 385 */
mptapton 2:bc7345c92188 386
mptapton 2:bc7345c92188 387 //clearLEDstrip();
mptapton 2:bc7345c92188 388 }
mptapton 2:bc7345c92188 389 }
mptapton 2:bc7345c92188 390 else //if myinputpin Chord or Tuner mode = Chord mode selected
mptapton 2:bc7345c92188 391 { // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
mptapton 2:bc7345c92188 392 // ..............CHORD MODE.........................
mptapton 2:bc7345c92188 393 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
mptapton 2:bc7345c92188 394 while(1)
mptapton 2:bc7345c92188 395 {
mptapton 2:bc7345c92188 396 ledd1=0; //received character from mbed1
mptapton 2:bc7345c92188 397 ledd2=intune; //intune input from mbed1
mptapton 2:bc7345c92188 398 ledd3=toohigh; // toohigh input from mbed1
mptapton 2:bc7345c92188 399 ledd4=state;// state input from mbed1
mptapton 2:bc7345c92188 400 // pc.putc(typed[0]); //debugging
mptapton 2:bc7345c92188 401 chordCode = decoder(typed); //takes input char from mbed1 and gives back 0-6 to represent chord selected A-G
mptapton 2:bc7345c92188 402 shaper(chordCode, 0); //light current chord in white (0)
mptapton 2:bc7345c92188 403 wait(0.8); //hold it for a period so user can see it
mptapton 2:bc7345c92188 404 if (intune) //read mbed1 intune pin and light the green LEDs
taptoneesarm 0:5ddd4b0f64f8 405 {
mptapton 2:bc7345c92188 406 shaper(chordCode, 1); //green light (1)
mptapton 2:bc7345c92188 407 wait(0.4);
taptoneesarm 0:5ddd4b0f64f8 408 }
mptapton 2:bc7345c92188 409 if ((toohigh) || (toolow))//read mbed1 toohigh and toolow pins and light the red LEDs
mptapton 2:bc7345c92188 410 {
mptapton 2:bc7345c92188 411 shaper(chordCode, -1); //red light (-1)
mptapton 2:bc7345c92188 412 wait(0.4);
mptapton 2:bc7345c92188 413 }
mptapton 2:bc7345c92188 414 clearLEDstrip();
mptapton 2:bc7345c92188 415 }
mptapton 2:bc7345c92188 416 }
taptoneesarm 0:5ddd4b0f64f8 417 }