School project big bang base code
Dependencies: PololuLedStrip mbed
Fork of SX10_BigBangFinal_A by
main.cpp@2:ed13cfe20d33, 2017-02-06 (annotated)
- Committer:
- mptapton
- Date:
- Mon Feb 06 13:10:54 2017 +0000
- Revision:
- 2:ed13cfe20d33
- Parent:
- 1:e4d11295b3f4
Tapton school guitar project base for BB
Who changed what in which revision?
User | Revision | Line number | New 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:ed13cfe20d33 | 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:ed13cfe20d33 | 10 | DigitalIn intune(p19); |
mptapton | 2:ed13cfe20d33 | 11 | DigitalIn toohigh(p18); |
mptapton | 2:ed13cfe20d33 | 12 | DigitalIn toolow(p17); |
mptapton | 2:ed13cfe20d33 | 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:ed13cfe20d33 | 18 | DigitalIn myInputPin (p21); //select tuner or chord learning mode |
mptapton | 1:e4d11295b3f4 | 19 | |
mptapton | 2:ed13cfe20d33 | 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:ed13cfe20d33 | 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:ed13cfe20d33 | 36 | int lowEstring[6] = {0,11,12,23,24,35}; //<<<< STRINGS supported in Tuner mode for LED strip |
mptapton | 2:ed13cfe20d33 | 37 | int Astring[6] = {1,10,13,22,25,34}; |
mptapton | 2:ed13cfe20d33 | 38 | int Dstring[6] = {2,9,14,21,26,33}; |
mptapton | 2:ed13cfe20d33 | 39 | int Gstring[6] = {3,8,15,20,27,32}; |
mptapton | 2:ed13cfe20d33 | 40 | int Bstring[6] = {4,7,16,19,28,31}; |
mptapton | 2:ed13cfe20d33 | 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:ed13cfe20d33 | 89 | int ascii = int(typed[0]);// get the hex value for input char from mbed1 |
mptapton | 2:ed13cfe20d33 | 90 | int chordValue; //set up integer 0-6 to represent A-G for later |
mptapton | 2:ed13cfe20d33 | 91 | if (65 <= ascii && ascii <= 71) //test if mbed1 input is a major chord A-G |
mptapton | 2:ed13cfe20d33 | 92 | { |
mptapton | 2:ed13cfe20d33 | 93 | chordValue = ascii - 65; // it is A-G so set int to appropriate 0-6 |
mptapton | 2:ed13cfe20d33 | 94 | // pc.printf(" %d ", chordValue); |
mptapton | 2:ed13cfe20d33 | 95 | /* |
mptapton | 2:ed13cfe20d33 | 96 | switch (chordValue) { //for diagnostics use putc not printf to send |
mptapton | 2:ed13cfe20d33 | 97 | case 0: //received char from mbed1 to mbed2's usb pc |
mptapton | 2:ed13cfe20d33 | 98 | pc.putc('A'); |
mptapton | 2:ed13cfe20d33 | 99 | break; |
mptapton | 2:ed13cfe20d33 | 100 | case 1: |
mptapton | 2:ed13cfe20d33 | 101 | pc.putc('B'); |
mptapton | 2:ed13cfe20d33 | 102 | break; |
mptapton | 2:ed13cfe20d33 | 103 | case 2: |
mptapton | 2:ed13cfe20d33 | 104 | pc.putc('C'); |
mptapton | 2:ed13cfe20d33 | 105 | break; |
mptapton | 2:ed13cfe20d33 | 106 | case 3: |
mptapton | 2:ed13cfe20d33 | 107 | pc.putc('D'); |
mptapton | 2:ed13cfe20d33 | 108 | break; |
mptapton | 2:ed13cfe20d33 | 109 | case 4: |
mptapton | 2:ed13cfe20d33 | 110 | pc.putc('E'); |
mptapton | 2:ed13cfe20d33 | 111 | break; |
mptapton | 2:ed13cfe20d33 | 112 | case 5: |
mptapton | 2:ed13cfe20d33 | 113 | pc.putc('F'); |
mptapton | 2:ed13cfe20d33 | 114 | break; |
mptapton | 2:ed13cfe20d33 | 115 | case 6: |
mptapton | 2:ed13cfe20d33 | 116 | pc.putc('G'); |
mptapton | 2:ed13cfe20d33 | 117 | break; |
mptapton | 2:ed13cfe20d33 | 118 | } |
mptapton | 2:ed13cfe20d33 | 119 | */ |
mptapton | 2:ed13cfe20d33 | 120 | } |
mptapton | 2:ed13cfe20d33 | 121 | return chordValue; |
taptoneesarm | 0:5ddd4b0f64f8 | 122 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 123 | |
mptapton | 2:ed13cfe20d33 | 124 | int tunerdecoder(string typed) |
mptapton | 2:ed13cfe20d33 | 125 | { |
mptapton | 2:ed13cfe20d33 | 126 | int ascii = int(typed[0]);// get the hex value for input char from mbed1 |
mptapton | 2:ed13cfe20d33 | 127 | int chordValue; //set up integer 0-6 to represent A-G for later |
mptapton | 2:ed13cfe20d33 | 128 | // if (65 <= ascii && ascii <= 71) //test if mbed1 input is a major chord A-G |
mptapton | 2:ed13cfe20d33 | 129 | // { |
mptapton | 2:ed13cfe20d33 | 130 | // chordValue = ascii - 65; // it is A-G so set int to appropriate 0-6 |
mptapton | 2:ed13cfe20d33 | 131 | // pc.printf(" %d ", chordValue); |
mptapton | 2:ed13cfe20d33 | 132 | |
mptapton | 2:ed13cfe20d33 | 133 | switch (ascii) { //for diagnostics use putc not printf to send |
mptapton | 2:ed13cfe20d33 | 134 | case 69: //received char from mbed1 to mbed2's usb pc |
mptapton | 2:ed13cfe20d33 | 135 | pc.putc('E'); |
mptapton | 2:ed13cfe20d33 | 136 | chordValue=0; |
mptapton | 2:ed13cfe20d33 | 137 | break; |
mptapton | 2:ed13cfe20d33 | 138 | case 65: |
mptapton | 2:ed13cfe20d33 | 139 | pc.putc('A'); |
mptapton | 2:ed13cfe20d33 | 140 | chordValue=1; |
mptapton | 2:ed13cfe20d33 | 141 | break; |
mptapton | 2:ed13cfe20d33 | 142 | case 68: |
mptapton | 2:ed13cfe20d33 | 143 | chordValue=2; |
mptapton | 2:ed13cfe20d33 | 144 | pc.putc('D'); |
mptapton | 2:ed13cfe20d33 | 145 | break; |
mptapton | 2:ed13cfe20d33 | 146 | case 71: |
mptapton | 2:ed13cfe20d33 | 147 | chordValue=3; |
mptapton | 2:ed13cfe20d33 | 148 | pc.putc('G'); |
mptapton | 2:ed13cfe20d33 | 149 | break; |
mptapton | 2:ed13cfe20d33 | 150 | case 66: |
mptapton | 2:ed13cfe20d33 | 151 | chordValue=4; |
mptapton | 2:ed13cfe20d33 | 152 | pc.putc('B'); |
mptapton | 2:ed13cfe20d33 | 153 | break; |
mptapton | 2:ed13cfe20d33 | 154 | case 101: |
mptapton | 2:ed13cfe20d33 | 155 | chordValue=5; |
mptapton | 2:ed13cfe20d33 | 156 | pc.putc('e'); |
mptapton | 2:ed13cfe20d33 | 157 | break; |
mptapton | 2:ed13cfe20d33 | 158 | // case 71: |
mptapton | 2:ed13cfe20d33 | 159 | // pc.putc('G'); |
mptapton | 2:ed13cfe20d33 | 160 | // break; |
mptapton | 2:ed13cfe20d33 | 161 | // } |
mptapton | 2:ed13cfe20d33 | 162 | |
mptapton | 2:ed13cfe20d33 | 163 | } |
mptapton | 2:ed13cfe20d33 | 164 | // if (ascii == 101) //test if mbed1 input is High E sent as 'e' |
mptapton | 2:ed13cfe20d33 | 165 | // { |
mptapton | 2:ed13cfe20d33 | 166 | // chordValue = 5; |
mptapton | 2:ed13cfe20d33 | 167 | // } |
mptapton | 2:ed13cfe20d33 | 168 | return chordValue; |
mptapton | 2:ed13cfe20d33 | 169 | } |
mptapton | 2:ed13cfe20d33 | 170 | |
mptapton | 2:ed13cfe20d33 | 171 | |
taptoneesarm | 0:5ddd4b0f64f8 | 172 | void illuminator (int position, int colour) |
taptoneesarm | 0:5ddd4b0f64f8 | 173 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 174 | //pc.printf ("Position: %d Colour: %d\n",position,colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 175 | if (position != -1) |
taptoneesarm | 0:5ddd4b0f64f8 | 176 | { |
mptapton | 1:e4d11295b3f4 | 177 | if (colour == -1) //out of tune |
taptoneesarm | 0:5ddd4b0f64f8 | 178 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 179 | colors[position] = (rgb_color){40,0,0}; |
taptoneesarm | 0:5ddd4b0f64f8 | 180 | } |
mptapton | 1:e4d11295b3f4 | 181 | else if (colour == 0) // processing |
taptoneesarm | 0:5ddd4b0f64f8 | 182 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 183 | colors[position] = (rgb_color){40,40,40}; |
taptoneesarm | 0:5ddd4b0f64f8 | 184 | } |
mptapton | 1:e4d11295b3f4 | 185 | else if (colour == 1) //in tune |
taptoneesarm | 0:5ddd4b0f64f8 | 186 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 187 | colors[position] = (rgb_color){0,40,0}; |
taptoneesarm | 0:5ddd4b0f64f8 | 188 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 189 | else |
taptoneesarm | 0:5ddd4b0f64f8 | 190 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 191 | pc.printf ("Error: invalid colour number in illuminator\n"); |
taptoneesarm | 0:5ddd4b0f64f8 | 192 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 193 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 194 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 195 | |
mptapton | 2:ed13cfe20d33 | 196 | |
mptapton | 2:ed13cfe20d33 | 197 | //Possible to change to a case/switch structure improve speed? |
mptapton | 2:ed13cfe20d33 | 198 | int shaper (int shape, int colour)// <<<<<< CHORD SHAPER >>>>>>> |
mptapton | 2:ed13cfe20d33 | 199 | { |
mptapton | 2:ed13cfe20d33 | 200 | if (shape == 0) |
mptapton | 2:ed13cfe20d33 | 201 | { |
mptapton | 2:ed13cfe20d33 | 202 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 203 | { |
mptapton | 2:ed13cfe20d33 | 204 | illuminator (ledMapping(aMajor[i],i+1), colour); |
mptapton | 2:ed13cfe20d33 | 205 | } |
mptapton | 2:ed13cfe20d33 | 206 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 207 | } |
mptapton | 2:ed13cfe20d33 | 208 | else if (shape == 1) |
mptapton | 2:ed13cfe20d33 | 209 | { |
mptapton | 2:ed13cfe20d33 | 210 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 211 | { |
mptapton | 2:ed13cfe20d33 | 212 | illuminator (ledMapping(bMajor[i],i+1), colour); |
mptapton | 2:ed13cfe20d33 | 213 | } |
mptapton | 2:ed13cfe20d33 | 214 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 215 | |
mptapton | 2:ed13cfe20d33 | 216 | } |
mptapton | 2:ed13cfe20d33 | 217 | else if (shape == 2) |
mptapton | 2:ed13cfe20d33 | 218 | { |
mptapton | 2:ed13cfe20d33 | 219 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 220 | { |
mptapton | 2:ed13cfe20d33 | 221 | illuminator (ledMapping(cMajor[i],i+1), colour); |
mptapton | 2:ed13cfe20d33 | 222 | } |
mptapton | 2:ed13cfe20d33 | 223 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 224 | } |
mptapton | 2:ed13cfe20d33 | 225 | else if (shape == 3) |
mptapton | 2:ed13cfe20d33 | 226 | { |
mptapton | 2:ed13cfe20d33 | 227 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 228 | { |
mptapton | 2:ed13cfe20d33 | 229 | illuminator (ledMapping(dMajor[i],i+1), colour); |
mptapton | 2:ed13cfe20d33 | 230 | } |
mptapton | 2:ed13cfe20d33 | 231 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 232 | } |
mptapton | 2:ed13cfe20d33 | 233 | else if (shape == 4) |
mptapton | 2:ed13cfe20d33 | 234 | { |
mptapton | 2:ed13cfe20d33 | 235 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 236 | { |
mptapton | 2:ed13cfe20d33 | 237 | illuminator (ledMapping(eMajor[i],i+1), colour); |
mptapton | 2:ed13cfe20d33 | 238 | } |
mptapton | 2:ed13cfe20d33 | 239 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 240 | } |
mptapton | 2:ed13cfe20d33 | 241 | else if (shape == 5) |
mptapton | 2:ed13cfe20d33 | 242 | { |
mptapton | 2:ed13cfe20d33 | 243 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 244 | { |
mptapton | 2:ed13cfe20d33 | 245 | illuminator (ledMapping(fMajor[i],i+1), colour); |
mptapton | 2:ed13cfe20d33 | 246 | } |
mptapton | 2:ed13cfe20d33 | 247 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 248 | } |
mptapton | 2:ed13cfe20d33 | 249 | else if (shape == 6) |
mptapton | 2:ed13cfe20d33 | 250 | { |
mptapton | 2:ed13cfe20d33 | 251 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 252 | { |
mptapton | 2:ed13cfe20d33 | 253 | illuminator (ledMapping(gMajor[i],i+1), colour); |
mptapton | 2:ed13cfe20d33 | 254 | } |
mptapton | 2:ed13cfe20d33 | 255 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 256 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 257 | |
mptapton | 2:ed13cfe20d33 | 258 | // Send the colors to the LED strip. |
mptapton | 2:ed13cfe20d33 | 259 | ledStrip.write(colors, LED_COUNT); |
mptapton | 2:ed13cfe20d33 | 260 | return (0); |
taptoneesarm | 0:5ddd4b0f64f8 | 261 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 262 | |
mptapton | 2:ed13cfe20d33 | 263 | //Possible to change to a case/switch structure improve speed? |
mptapton | 2:ed13cfe20d33 | 264 | int Tunershaper (int shape, int colour) // <<<<<<<< TUNER SHAPER >>>>>>>>> |
mptapton | 2:ed13cfe20d33 | 265 | { |
mptapton | 2:ed13cfe20d33 | 266 | if (shape == 0) |
mptapton | 2:ed13cfe20d33 | 267 | { |
mptapton | 2:ed13cfe20d33 | 268 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 269 | { |
mptapton | 2:ed13cfe20d33 | 270 | illuminator (lowEstring[i], colour); |
mptapton | 2:ed13cfe20d33 | 271 | } |
mptapton | 2:ed13cfe20d33 | 272 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 273 | } |
mptapton | 2:ed13cfe20d33 | 274 | else if (shape == 1) |
mptapton | 2:ed13cfe20d33 | 275 | { |
mptapton | 2:ed13cfe20d33 | 276 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 277 | { |
mptapton | 2:ed13cfe20d33 | 278 | illuminator (Astring[i], colour); |
mptapton | 2:ed13cfe20d33 | 279 | } |
mptapton | 2:ed13cfe20d33 | 280 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 281 | |
mptapton | 2:ed13cfe20d33 | 282 | } |
mptapton | 2:ed13cfe20d33 | 283 | else if (shape == 2) |
mptapton | 2:ed13cfe20d33 | 284 | { |
mptapton | 2:ed13cfe20d33 | 285 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 286 | { |
mptapton | 2:ed13cfe20d33 | 287 | illuminator (Dstring[i], colour); |
mptapton | 2:ed13cfe20d33 | 288 | } |
mptapton | 2:ed13cfe20d33 | 289 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 290 | } |
mptapton | 2:ed13cfe20d33 | 291 | else if (shape == 3) |
mptapton | 2:ed13cfe20d33 | 292 | { |
mptapton | 2:ed13cfe20d33 | 293 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 294 | { |
mptapton | 2:ed13cfe20d33 | 295 | illuminator (Gstring[i], colour); |
mptapton | 2:ed13cfe20d33 | 296 | } |
mptapton | 2:ed13cfe20d33 | 297 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 298 | } |
mptapton | 2:ed13cfe20d33 | 299 | else if (shape == 4) |
mptapton | 2:ed13cfe20d33 | 300 | { |
mptapton | 2:ed13cfe20d33 | 301 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 302 | { |
mptapton | 2:ed13cfe20d33 | 303 | illuminator (Bstring[i], colour); |
mptapton | 2:ed13cfe20d33 | 304 | } |
mptapton | 2:ed13cfe20d33 | 305 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 306 | } |
mptapton | 2:ed13cfe20d33 | 307 | else if (shape == 5) |
mptapton | 2:ed13cfe20d33 | 308 | { |
mptapton | 2:ed13cfe20d33 | 309 | for(int i = 0; i<6; i++) |
mptapton | 2:ed13cfe20d33 | 310 | { |
mptapton | 2:ed13cfe20d33 | 311 | illuminator (HiEstring[i], colour); |
mptapton | 2:ed13cfe20d33 | 312 | } |
mptapton | 2:ed13cfe20d33 | 313 | // feedback(colour); |
mptapton | 2:ed13cfe20d33 | 314 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 315 | |
mptapton | 2:ed13cfe20d33 | 316 | // Send the colors to the LED strip. |
mptapton | 2:ed13cfe20d33 | 317 | ledStrip.write(colors, LED_COUNT); |
mptapton | 2:ed13cfe20d33 | 318 | return (0); |
taptoneesarm | 0:5ddd4b0f64f8 | 319 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 320 | |
mptapton | 2:ed13cfe20d33 | 321 | |
mptapton | 2:ed13cfe20d33 | 322 | void clearLEDstrip() //writes to all the LEDs to clear them |
mptapton | 2:ed13cfe20d33 | 323 | { |
mptapton | 2:ed13cfe20d33 | 324 | wait(0.2); |
mptapton | 2:ed13cfe20d33 | 325 | for(int i=0; i < LED_COUNT ; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 326 | { |
mptapton | 2:ed13cfe20d33 | 327 | colors[i] = (rgb_color){ 0, 0, 0 }; |
taptoneesarm | 0:5ddd4b0f64f8 | 328 | } |
mptapton | 2:ed13cfe20d33 | 329 | ledStrip.write(colors, LED_COUNT); |
mptapton | 2:ed13cfe20d33 | 330 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 331 | |
mptapton | 2:ed13cfe20d33 | 332 | void callback() //interrupt from serial port from mbed1 |
mptapton | 2:ed13cfe20d33 | 333 | { |
mptapton | 2:ed13cfe20d33 | 334 | ledd1=1; // received character from mbed1 |
mptapton | 2:ed13cfe20d33 | 335 | typed[0]=device.getc(); //get char from mbed1 via serial port |
mptapton | 2:ed13cfe20d33 | 336 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 337 | int main() |
taptoneesarm | 0:5ddd4b0f64f8 | 338 | { |
mptapton | 2:ed13cfe20d33 | 339 | pc.baud (115200); //for pc usb |
mptapton | 1:e4d11295b3f4 | 340 | device.baud(19200); //for communications with mbed 1 |
mptapton | 2:ed13cfe20d33 | 341 | myInputPin.mode(PullUp); //set the mbed to use a pullup resistor |
taptoneesarm | 0:5ddd4b0f64f8 | 342 | string chord; |
mptapton | 2:ed13cfe20d33 | 343 | int chordCode; |
mptapton | 2:ed13cfe20d33 | 344 | setbuf(stdin, NULL);//clear the serial input buffer |
mptapton | 2:ed13cfe20d33 | 345 | device.attach(&callback);// for serial interupt callback function |
mptapton | 2:ed13cfe20d33 | 346 | clearLEDstrip(); |
mptapton | 2:ed13cfe20d33 | 347 | |
mptapton | 2:ed13cfe20d33 | 348 | myInputPin.mode(PullUp); //set the mbed to use a pullup resistor |
mptapton | 2:ed13cfe20d33 | 349 | if (myInputPin) // <<<<SELECT GUITAR TUNER OR CHORD TRAINER FUNCTION>>> |
taptoneesarm | 0:5ddd4b0f64f8 | 350 | { |
mptapton | 2:ed13cfe20d33 | 351 | while(1) |
mptapton | 2:ed13cfe20d33 | 352 | { |
mptapton | 2:ed13cfe20d33 | 353 | clearLEDstrip(); |
mptapton | 2:ed13cfe20d33 | 354 | ledd1=0; //received character from mbed1 |
mptapton | 2:ed13cfe20d33 | 355 | ledd2=toolow; //inputs from mbed1 mapped onto mbed 2 LED's |
mptapton | 2:ed13cfe20d33 | 356 | ledd3=intune; // |
mptapton | 2:ed13cfe20d33 | 357 | ledd4=toohigh;// |
mptapton | 2:ed13cfe20d33 | 358 | // pc.putc(typed[0]); //debugging |
mptapton | 2:ed13cfe20d33 | 359 | chordCode = tunerdecoder(typed); //takes input char from mbed1 and gives back 0-6 to represent chord selected A-G |
mptapton | 2:ed13cfe20d33 | 360 | // pc.putc(chordCode); |
mptapton | 2:ed13cfe20d33 | 361 | |
mptapton | 2:ed13cfe20d33 | 362 | // shaper(chordCode, 0); //light current chord in white (0) |
mptapton | 2:ed13cfe20d33 | 363 | // wait(0.8); //hold it for a period so user can see it |
mptapton | 2:ed13cfe20d33 | 364 | if (intune) //read mbed1 intune pin and light the green LEDs |
mptapton | 2:ed13cfe20d33 | 365 | { |
mptapton | 2:ed13cfe20d33 | 366 | Tunershaper(chordCode, 1); //green light (1) |
mptapton | 2:ed13cfe20d33 | 367 | wait(0.4); |
mptapton | 2:ed13cfe20d33 | 368 | } |
mptapton | 2:ed13cfe20d33 | 369 | if (toohigh) //read mbed1 toohigh pin and light the red LEDs |
mptapton | 2:ed13cfe20d33 | 370 | { |
mptapton | 2:ed13cfe20d33 | 371 | Tunershaper(chordCode, -1); //red light (-1) |
mptapton | 2:ed13cfe20d33 | 372 | wait(0.4); |
mptapton | 2:ed13cfe20d33 | 373 | } |
mptapton | 2:ed13cfe20d33 | 374 | if (toolow)//read mbed1 toolow pins and light the red LEDs |
taptoneesarm | 0:5ddd4b0f64f8 | 375 | { |
mptapton | 2:ed13cfe20d33 | 376 | Tunershaper(chordCode, 0); //white light (0) |
mptapton | 2:ed13cfe20d33 | 377 | wait(0.4); |
mptapton | 2:ed13cfe20d33 | 378 | } |
mptapton | 2:ed13cfe20d33 | 379 | |
mptapton | 2:ed13cfe20d33 | 380 | |
mptapton | 2:ed13cfe20d33 | 381 | /* for(int j = 0; j<6; j++) |
mptapton | 2:ed13cfe20d33 | 382 | { |
mptapton | 2:ed13cfe20d33 | 383 | // chordCode=j; |
mptapton | 2:ed13cfe20d33 | 384 | Tunershaper(chordCode, -1); //red |
mptapton | 2:ed13cfe20d33 | 385 | wait(0.5); |
mptapton | 2:ed13cfe20d33 | 386 | ledStrip.write(colors, LED_COUNT); |
mptapton | 2:ed13cfe20d33 | 387 | } |
mptapton | 2:ed13cfe20d33 | 388 | for(int j = 0; j<6; j++) |
mptapton | 2:ed13cfe20d33 | 389 | { |
mptapton | 2:ed13cfe20d33 | 390 | // chordCode=j; |
mptapton | 2:ed13cfe20d33 | 391 | Tunershaper(chordCode, 1); //green |
mptapton | 2:ed13cfe20d33 | 392 | wait(0.5); |
mptapton | 2:ed13cfe20d33 | 393 | ledStrip.write(colors, LED_COUNT); |
mptapton | 2:ed13cfe20d33 | 394 | } |
mptapton | 2:ed13cfe20d33 | 395 | for(int j = 0; j<6; j++) |
mptapton | 2:ed13cfe20d33 | 396 | { |
mptapton | 2:ed13cfe20d33 | 397 | // chordCode=j; |
mptapton | 2:ed13cfe20d33 | 398 | Tunershaper(chordCode, 0); //green |
mptapton | 2:ed13cfe20d33 | 399 | wait(0.5); |
mptapton | 2:ed13cfe20d33 | 400 | ledStrip.write(colors, LED_COUNT); |
taptoneesarm | 0:5ddd4b0f64f8 | 401 | } |
mptapton | 2:ed13cfe20d33 | 402 | |
mptapton | 2:ed13cfe20d33 | 403 | chordCode=0; |
mptapton | 2:ed13cfe20d33 | 404 | Tunershaper(chordCode, 0); //white |
mptapton | 2:ed13cfe20d33 | 405 | wait(0.5); |
mptapton | 2:ed13cfe20d33 | 406 | ledStrip.write(colors, LED_COUNT); |
mptapton | 2:ed13cfe20d33 | 407 | |
mptapton | 2:ed13cfe20d33 | 408 | chordCode=1; |
mptapton | 2:ed13cfe20d33 | 409 | Tunershaper(chordCode, 0); //white |
mptapton | 2:ed13cfe20d33 | 410 | wait(0.5); |
mptapton | 2:ed13cfe20d33 | 411 | ledStrip.write(colors, LED_COUNT); |
mptapton | 2:ed13cfe20d33 | 412 | |
mptapton | 2:ed13cfe20d33 | 413 | chordCode=2; |
mptapton | 2:ed13cfe20d33 | 414 | Tunershaper(chordCode, 0); //white |
mptapton | 2:ed13cfe20d33 | 415 | wait(0.5); |
mptapton | 2:ed13cfe20d33 | 416 | ledStrip.write(colors, LED_COUNT); |
mptapton | 2:ed13cfe20d33 | 417 | |
mptapton | 2:ed13cfe20d33 | 418 | chordCode=3; |
mptapton | 2:ed13cfe20d33 | 419 | Tunershaper(chordCode, 0); //white |
mptapton | 2:ed13cfe20d33 | 420 | wait(0.5); |
mptapton | 2:ed13cfe20d33 | 421 | ledStrip.write(colors, LED_COUNT); |
mptapton | 2:ed13cfe20d33 | 422 | |
mptapton | 2:ed13cfe20d33 | 423 | chordCode=4; |
mptapton | 2:ed13cfe20d33 | 424 | Tunershaper(chordCode, 0); //white |
mptapton | 2:ed13cfe20d33 | 425 | wait(0.5); |
mptapton | 2:ed13cfe20d33 | 426 | ledStrip.write(colors, LED_COUNT); |
mptapton | 2:ed13cfe20d33 | 427 | |
mptapton | 2:ed13cfe20d33 | 428 | chordCode=5; |
mptapton | 2:ed13cfe20d33 | 429 | Tunershaper(chordCode, 0); //white |
mptapton | 2:ed13cfe20d33 | 430 | wait(0.5); |
mptapton | 2:ed13cfe20d33 | 431 | ledStrip.write(colors, LED_COUNT); |
mptapton | 2:ed13cfe20d33 | 432 | */ |
mptapton | 2:ed13cfe20d33 | 433 | |
mptapton | 2:ed13cfe20d33 | 434 | //clearLEDstrip(); |
mptapton | 2:ed13cfe20d33 | 435 | } |
mptapton | 2:ed13cfe20d33 | 436 | } |
mptapton | 2:ed13cfe20d33 | 437 | else //if myinputpin Chord or Tuner mode = Chord mode selected |
mptapton | 2:ed13cfe20d33 | 438 | { // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
mptapton | 2:ed13cfe20d33 | 439 | // ..............CHORD MODE......................... |
mptapton | 2:ed13cfe20d33 | 440 | // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
mptapton | 2:ed13cfe20d33 | 441 | while(1) |
mptapton | 2:ed13cfe20d33 | 442 | { |
mptapton | 2:ed13cfe20d33 | 443 | ledd1=0; //received character from mbed1 |
mptapton | 2:ed13cfe20d33 | 444 | ledd2=intune; //intune input from mbed1 |
mptapton | 2:ed13cfe20d33 | 445 | ledd3=toohigh; // toohigh input from mbed1 |
mptapton | 2:ed13cfe20d33 | 446 | ledd4=state;// state input from mbed1 |
mptapton | 2:ed13cfe20d33 | 447 | // pc.putc(typed[0]); //debugging |
mptapton | 2:ed13cfe20d33 | 448 | chordCode = decoder(typed); //takes input char from mbed1 and gives back 0-6 to represent chord selected A-G |
mptapton | 2:ed13cfe20d33 | 449 | shaper(chordCode, 0); //light current chord in white (0) |
mptapton | 2:ed13cfe20d33 | 450 | wait(0.8); //hold it for a period so user can see it |
mptapton | 2:ed13cfe20d33 | 451 | if (intune) //read mbed1 intune pin and light the green LEDs |
taptoneesarm | 0:5ddd4b0f64f8 | 452 | { |
mptapton | 2:ed13cfe20d33 | 453 | shaper(chordCode, 1); //green light (1) |
mptapton | 2:ed13cfe20d33 | 454 | wait(0.4); |
taptoneesarm | 0:5ddd4b0f64f8 | 455 | } |
mptapton | 2:ed13cfe20d33 | 456 | if ((toohigh) || (toolow))//read mbed1 toohigh and toolow pins and light the red LEDs |
mptapton | 2:ed13cfe20d33 | 457 | { |
mptapton | 2:ed13cfe20d33 | 458 | shaper(chordCode, -1); //red light (-1) |
mptapton | 2:ed13cfe20d33 | 459 | wait(0.4); |
mptapton | 2:ed13cfe20d33 | 460 | } |
mptapton | 2:ed13cfe20d33 | 461 | clearLEDstrip(); |
mptapton | 2:ed13cfe20d33 | 462 | } |
mptapton | 2:ed13cfe20d33 | 463 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 464 | } |