![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
school project
Dependencies: PololuLedStrip mbed
main.cpp@0:5ddd4b0f64f8, 2017-01-26 (annotated)
- Committer:
- taptoneesarm
- Date:
- Thu Jan 26 11:00:15 2017 +0000
- Revision:
- 0:5ddd4b0f64f8
schooll led proiject
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 | |
taptoneesarm | 0:5ddd4b0f64f8 | 5 | #define LED_COUNT 60 |
taptoneesarm | 0:5ddd4b0f64f8 | 6 | |
taptoneesarm | 0:5ddd4b0f64f8 | 7 | Serial pc(USBTX, USBRX); // tx, rx |
taptoneesarm | 0:5ddd4b0f64f8 | 8 | |
taptoneesarm | 0:5ddd4b0f64f8 | 9 | PololuLedStrip ledStrip(p11); |
taptoneesarm | 0:5ddd4b0f64f8 | 10 | |
taptoneesarm | 0:5ddd4b0f64f8 | 11 | rgb_color colors[LED_COUNT]; |
taptoneesarm | 0:5ddd4b0f64f8 | 12 | |
taptoneesarm | 0:5ddd4b0f64f8 | 13 | Timer timer; |
taptoneesarm | 0:5ddd4b0f64f8 | 14 | |
taptoneesarm | 0:5ddd4b0f64f8 | 15 | int aMajor[6] = {0,2,2,2,0,-1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 16 | int bMajor[6] = {2,4,4,4,2,-1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 17 | int cMajor[6] = {0,1,0,2,3,-1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 18 | int dMajor[6] = {2,3,2,0,-1,-1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 19 | int eMajor[6] = {0,0,1,2,2,0}; |
taptoneesarm | 0:5ddd4b0f64f8 | 20 | int fMajor[6] = {1,-1,2,3,3,1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 21 | int gMajor[6] = {3,0,0,0,2,3}; |
taptoneesarm | 0:5ddd4b0f64f8 | 22 | |
taptoneesarm | 0:5ddd4b0f64f8 | 23 | int aMinor[6] = {0,1,2,2,0,-1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 24 | int bMinor[6] = {2,3,4,4,2,-1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 25 | int cMinor[6] = {3,4,5,5,3,-1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 26 | int dMinor[6] = {1,3,2,0,-1,-1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 27 | int eMinor[6] = {0,0,0,2,2,0}; |
taptoneesarm | 0:5ddd4b0f64f8 | 28 | int fMinor[6] = {1,1,1,3,3,1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 29 | int gMinor[6] = {-1,-1,-1,-1,0,0}; |
taptoneesarm | 0:5ddd4b0f64f8 | 30 | int gMinorActual[6] = {3,3,3,5,5,3}; |
taptoneesarm | 0:5ddd4b0f64f8 | 31 | |
taptoneesarm | 0:5ddd4b0f64f8 | 32 | int aSharpMajor[6] = {1,3,3,3,1,-1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 33 | int cSharpMajor[6] = {1,2,1,3,4,-1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 34 | int fSharpMajor[6] = {2,-1,3,4,4,2}; |
taptoneesarm | 0:5ddd4b0f64f8 | 35 | int gSharpMajor[6] = {4,1,1,1,3,4}; |
taptoneesarm | 0:5ddd4b0f64f8 | 36 | |
taptoneesarm | 0:5ddd4b0f64f8 | 37 | int aSharpMinor[6] = {1,2,3,3,1,-1}; |
taptoneesarm | 0:5ddd4b0f64f8 | 38 | int fSharpMinor[6] = {2,2,2,4,4,2}; |
taptoneesarm | 0:5ddd4b0f64f8 | 39 | |
taptoneesarm | 0:5ddd4b0f64f8 | 40 | /* |
taptoneesarm | 0:5ddd4b0f64f8 | 41 | Above are the various arrays which represent the location of the string |
taptoneesarm | 0:5ddd4b0f64f8 | 42 | played in a given fret to achieve a certain chord. The layout |
taptoneesarm | 0:5ddd4b0f64f8 | 43 | of this arrangement helps the mBed light up the correct pattern |
taptoneesarm | 0:5ddd4b0f64f8 | 44 | of LEDs on the LED strip. Not all of the chords can be played as the |
taptoneesarm | 0:5ddd4b0f64f8 | 45 | Solo only includes the first six frets. |
taptoneesarm | 0:5ddd4b0f64f8 | 46 | */ |
taptoneesarm | 0:5ddd4b0f64f8 | 47 | |
taptoneesarm | 0:5ddd4b0f64f8 | 48 | int chordCode = 0; |
taptoneesarm | 0:5ddd4b0f64f8 | 49 | int testResult = 0; |
taptoneesarm | 0:5ddd4b0f64f8 | 50 | int interpretedChordCode = 0; |
taptoneesarm | 0:5ddd4b0f64f8 | 51 | |
taptoneesarm | 0:5ddd4b0f64f8 | 52 | using namespace std; |
taptoneesarm | 0:5ddd4b0f64f8 | 53 | |
taptoneesarm | 0:5ddd4b0f64f8 | 54 | int ledMapping(int fret, int str) |
taptoneesarm | 0:5ddd4b0f64f8 | 55 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 56 | int result; |
taptoneesarm | 0:5ddd4b0f64f8 | 57 | // Initialise a variable that represents the specific number of the LED |
taptoneesarm | 0:5ddd4b0f64f8 | 58 | // that is to be lit up |
taptoneesarm | 0:5ddd4b0f64f8 | 59 | if(fret != -1) |
taptoneesarm | 0:5ddd4b0f64f8 | 60 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 61 | if(fret%2 != 0) |
taptoneesarm | 0:5ddd4b0f64f8 | 62 | // If the fret number is odd... |
taptoneesarm | 0:5ddd4b0f64f8 | 63 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 64 | result = 6*fret + str - 1; |
taptoneesarm | 0:5ddd4b0f64f8 | 65 | // ...then the LED number for that fret corresponds to the above formula |
taptoneesarm | 0:5ddd4b0f64f8 | 66 | } else |
taptoneesarm | 0:5ddd4b0f64f8 | 67 | // Otherwise if the fret number is even... |
taptoneesarm | 0:5ddd4b0f64f8 | 68 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 69 | result = 6*(fret + 1) - str; |
taptoneesarm | 0:5ddd4b0f64f8 | 70 | // ...then the LED number for that fret corresponds to the above formula |
taptoneesarm | 0:5ddd4b0f64f8 | 71 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 72 | return result; |
taptoneesarm | 0:5ddd4b0f64f8 | 73 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 74 | return -1; |
taptoneesarm | 0:5ddd4b0f64f8 | 75 | // Output the LED number as a return value so that other parts of the code can |
taptoneesarm | 0:5ddd4b0f64f8 | 76 | // use it when this function is called for a specific chord. |
taptoneesarm | 0:5ddd4b0f64f8 | 77 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 78 | |
taptoneesarm | 0:5ddd4b0f64f8 | 79 | /* |
taptoneesarm | 0:5ddd4b0f64f8 | 80 | * The decoder takes a char value that represents a chord, whether it is sharp or natural and whether |
taptoneesarm | 0:5ddd4b0f64f8 | 81 | * it is major or minor. The inputted value for chord is either a capital (major) or lowercase letter (minor). |
taptoneesarm | 0:5ddd4b0f64f8 | 82 | * Also assigned is a sharp value (either 0 or 1, where 0 is a natural note and 1 is a sharp) |
taptoneesarm | 0:5ddd4b0f64f8 | 83 | */ |
taptoneesarm | 0:5ddd4b0f64f8 | 84 | |
taptoneesarm | 0:5ddd4b0f64f8 | 85 | int decoder(string typed) |
taptoneesarm | 0:5ddd4b0f64f8 | 86 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 87 | int ascii = int(typed[0]); |
taptoneesarm | 0:5ddd4b0f64f8 | 88 | // Convert the first character in the array 's' and find its |
taptoneesarm | 0:5ddd4b0f64f8 | 89 | // hexadecimal code as a reference |
taptoneesarm | 0:5ddd4b0f64f8 | 90 | int chordValue; |
taptoneesarm | 0:5ddd4b0f64f8 | 91 | // Initialise a variable associated with the result so we can |
taptoneesarm | 0:5ddd4b0f64f8 | 92 | // assess it later |
taptoneesarm | 0:5ddd4b0f64f8 | 93 | if (65 <= ascii && ascii <= 71) |
taptoneesarm | 0:5ddd4b0f64f8 | 94 | // If its hexadecimal number corresponds to a uppercase letter |
taptoneesarm | 0:5ddd4b0f64f8 | 95 | // such that it is a major chord and... |
taptoneesarm | 0:5ddd4b0f64f8 | 96 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 97 | if (typed.size() == 1) |
taptoneesarm | 0:5ddd4b0f64f8 | 98 | // ...if the input is only one letter/symbol... |
taptoneesarm | 0:5ddd4b0f64f8 | 99 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 100 | chordValue = ascii - 65; |
taptoneesarm | 0:5ddd4b0f64f8 | 101 | // ...then offset the hexadecimal code of that letter by 65 |
taptoneesarm | 0:5ddd4b0f64f8 | 102 | // to map it back to the original list of non-sharp major chords and |
taptoneesarm | 0:5ddd4b0f64f8 | 103 | // store that value. |
taptoneesarm | 0:5ddd4b0f64f8 | 104 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 105 | else |
taptoneesarm | 0:5ddd4b0f64f8 | 106 | // ...if the input is more than one letter/symbol then assume |
taptoneesarm | 0:5ddd4b0f64f8 | 107 | // a hash (#) was entered to indicate a sharp value so... |
taptoneesarm | 0:5ddd4b0f64f8 | 108 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 109 | chordValue = ascii - 51; |
taptoneesarm | 0:5ddd4b0f64f8 | 110 | // ...offset the hexadecimal code by 51 to map it back to |
taptoneesarm | 0:5ddd4b0f64f8 | 111 | // the original list of sharp major chords and store that value. |
taptoneesarm | 0:5ddd4b0f64f8 | 112 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 113 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 114 | else if (97 <= ascii && ascii <= 103) |
taptoneesarm | 0:5ddd4b0f64f8 | 115 | // If its hexadecimal number corresponds to a lowercase letter |
taptoneesarm | 0:5ddd4b0f64f8 | 116 | // such that it is a minor chord and... |
taptoneesarm | 0:5ddd4b0f64f8 | 117 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 118 | if (typed.size() == 1) |
taptoneesarm | 0:5ddd4b0f64f8 | 119 | // ...if the input is only one letter/symbol... |
taptoneesarm | 0:5ddd4b0f64f8 | 120 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 121 | chordValue = ascii - 90; |
taptoneesarm | 0:5ddd4b0f64f8 | 122 | // ...then offset the hexadecimal code by 90 to map it back to |
taptoneesarm | 0:5ddd4b0f64f8 | 123 | // the original list of non-sharp minor chords and store that value. |
taptoneesarm | 0:5ddd4b0f64f8 | 124 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 125 | else |
taptoneesarm | 0:5ddd4b0f64f8 | 126 | // ...if the input is more than one letter/symbol then assume |
taptoneesarm | 0:5ddd4b0f64f8 | 127 | // a hash (#) was entered to indicate a sharp value so... |
taptoneesarm | 0:5ddd4b0f64f8 | 128 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 129 | chordValue = ascii - 76; |
taptoneesarm | 0:5ddd4b0f64f8 | 130 | // ...offset the hexadecimal code by 51 to map it back to |
taptoneesarm | 0:5ddd4b0f64f8 | 131 | // the original list of sharp minor chords and store that value. |
taptoneesarm | 0:5ddd4b0f64f8 | 132 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 133 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 134 | else |
taptoneesarm | 0:5ddd4b0f64f8 | 135 | // If the typed character does not correspond to an existing chord then... |
taptoneesarm | 0:5ddd4b0f64f8 | 136 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 137 | pc.printf("Incorrect input\n"); |
taptoneesarm | 0:5ddd4b0f64f8 | 138 | // Output an error message that indicates an incorrect input by the |
taptoneesarm | 0:5ddd4b0f64f8 | 139 | // user and... |
taptoneesarm | 0:5ddd4b0f64f8 | 140 | return(-99); |
taptoneesarm | 0:5ddd4b0f64f8 | 141 | // ...output -99 to indicate an error has occured to other parts of |
taptoneesarm | 0:5ddd4b0f64f8 | 142 | // the code. |
taptoneesarm | 0:5ddd4b0f64f8 | 143 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 144 | |
taptoneesarm | 0:5ddd4b0f64f8 | 145 | if (typed.size() > 2) |
taptoneesarm | 0:5ddd4b0f64f8 | 146 | // If the user input is greater than two characters then... |
taptoneesarm | 0:5ddd4b0f64f8 | 147 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 148 | pc.printf("Incorrect input\n"); |
taptoneesarm | 0:5ddd4b0f64f8 | 149 | // Output an error message that indicates an incorrect input by the |
taptoneesarm | 0:5ddd4b0f64f8 | 150 | // user and... |
taptoneesarm | 0:5ddd4b0f64f8 | 151 | return(-99); |
taptoneesarm | 0:5ddd4b0f64f8 | 152 | // ...output -99 to indicate an error has occured to other parts of |
taptoneesarm | 0:5ddd4b0f64f8 | 153 | // the code. |
taptoneesarm | 0:5ddd4b0f64f8 | 154 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 155 | |
taptoneesarm | 0:5ddd4b0f64f8 | 156 | if (chordValue != 15 && chordValue != 17 && chordValue != 18 && chordValue != 22 && chordValue != 23 && chordValue != 24 && chordValue != 25 && chordValue != 27) |
taptoneesarm | 0:5ddd4b0f64f8 | 157 | // If the obtained chord value corresponds to a chord that can actually be |
taptoneesarm | 0:5ddd4b0f64f8 | 158 | // played by Solo then... |
taptoneesarm | 0:5ddd4b0f64f8 | 159 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 160 | return chordValue; |
taptoneesarm | 0:5ddd4b0f64f8 | 161 | // ...output that chord value |
taptoneesarm | 0:5ddd4b0f64f8 | 162 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 163 | else |
taptoneesarm | 0:5ddd4b0f64f8 | 164 | // If the chord value corresponds to a chord that cannot be played by Solo or |
taptoneesarm | 0:5ddd4b0f64f8 | 165 | // is not even in the original table of chords then... |
taptoneesarm | 0:5ddd4b0f64f8 | 166 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 167 | pc.printf("This chord will not be played by the Solo\n"); |
taptoneesarm | 0:5ddd4b0f64f8 | 168 | // Output an error message that indicates a chord that cannot be played by the |
taptoneesarm | 0:5ddd4b0f64f8 | 169 | // Solo and... |
taptoneesarm | 0:5ddd4b0f64f8 | 170 | return -1; |
taptoneesarm | 0:5ddd4b0f64f8 | 171 | // ...output -1 to indicate an error with the input |
taptoneesarm | 0:5ddd4b0f64f8 | 172 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 173 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 174 | |
taptoneesarm | 0:5ddd4b0f64f8 | 175 | void illuminator (int position, int colour) |
taptoneesarm | 0:5ddd4b0f64f8 | 176 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 177 | //pc.printf ("Position: %d Colour: %d\n",position,colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 178 | if (position != -1) |
taptoneesarm | 0:5ddd4b0f64f8 | 179 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 180 | if (colour == -1) |
taptoneesarm | 0:5ddd4b0f64f8 | 181 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 182 | colors[position] = (rgb_color){40,0,0}; |
taptoneesarm | 0:5ddd4b0f64f8 | 183 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 184 | else if (colour == 0) |
taptoneesarm | 0:5ddd4b0f64f8 | 185 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 186 | colors[position] = (rgb_color){40,40,40}; |
taptoneesarm | 0:5ddd4b0f64f8 | 187 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 188 | else if (colour == 1) |
taptoneesarm | 0:5ddd4b0f64f8 | 189 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 190 | colors[position] = (rgb_color){0,40,0}; |
taptoneesarm | 0:5ddd4b0f64f8 | 191 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 192 | else |
taptoneesarm | 0:5ddd4b0f64f8 | 193 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 194 | pc.printf ("Error: invalid colour number in illuminator\n"); |
taptoneesarm | 0:5ddd4b0f64f8 | 195 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 196 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 197 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 198 | |
taptoneesarm | 0:5ddd4b0f64f8 | 199 | void feedback(int colour) |
taptoneesarm | 0:5ddd4b0f64f8 | 200 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 201 | if (colour == 1) |
taptoneesarm | 0:5ddd4b0f64f8 | 202 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 203 | pc.printf("Great Job!\n"); |
taptoneesarm | 0:5ddd4b0f64f8 | 204 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 205 | else if (colour == 0) |
taptoneesarm | 0:5ddd4b0f64f8 | 206 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 207 | pc.printf("Processing...\n"); |
taptoneesarm | 0:5ddd4b0f64f8 | 208 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 209 | else if (colour == -1) |
taptoneesarm | 0:5ddd4b0f64f8 | 210 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 211 | pc.printf("You suck!\n"); |
taptoneesarm | 0:5ddd4b0f64f8 | 212 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 213 | else |
taptoneesarm | 0:5ddd4b0f64f8 | 214 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 215 | pc.printf("Error: Colour input incorrect"); |
taptoneesarm | 0:5ddd4b0f64f8 | 216 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 217 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 218 | |
taptoneesarm | 0:5ddd4b0f64f8 | 219 | void identifier(int shape) |
taptoneesarm | 0:5ddd4b0f64f8 | 220 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 221 | int list; |
taptoneesarm | 0:5ddd4b0f64f8 | 222 | // Initialise an integer variable 'result' that represents the list a chord belongs to. |
taptoneesarm | 0:5ddd4b0f64f8 | 223 | int position; |
taptoneesarm | 0:5ddd4b0f64f8 | 224 | // Initialise an integer variable 'position' that represents the chord's relative position |
taptoneesarm | 0:5ddd4b0f64f8 | 225 | // in its allocated list. |
taptoneesarm | 0:5ddd4b0f64f8 | 226 | const char* letter; |
taptoneesarm | 0:5ddd4b0f64f8 | 227 | // Intialise a character variable 'letter' that will store the letter of the chord (A to G) |
taptoneesarm | 0:5ddd4b0f64f8 | 228 | string type; |
taptoneesarm | 0:5ddd4b0f64f8 | 229 | // Initialise a string (sentence) variable 'type' that will store the type of the chord |
taptoneesarm | 0:5ddd4b0f64f8 | 230 | // e.g. "Sharp Minor" or "Major" etc. |
taptoneesarm | 0:5ddd4b0f64f8 | 231 | |
taptoneesarm | 0:5ddd4b0f64f8 | 232 | list = int(shape/7); |
taptoneesarm | 0:5ddd4b0f64f8 | 233 | // Set the value of the 'list' variable to correspond to the list to which |
taptoneesarm | 0:5ddd4b0f64f8 | 234 | // the chord (represented by 'shape') belongs to. Each list holds 7 chords |
taptoneesarm | 0:5ddd4b0f64f8 | 235 | // relating to the first 7 letters of the alphabet (A to G). Therefore the list |
taptoneesarm | 0:5ddd4b0f64f8 | 236 | // a chord originates from can be determined by interpreting the integer value |
taptoneesarm | 0:5ddd4b0f64f8 | 237 | // the chord rounds down to, when its value is divided by seven. For example... |
taptoneesarm | 0:5ddd4b0f64f8 | 238 | |
taptoneesarm | 0:5ddd4b0f64f8 | 239 | if (list == 0) |
taptoneesarm | 0:5ddd4b0f64f8 | 240 | // ...if the chord comes from list '0', then it must be... |
taptoneesarm | 0:5ddd4b0f64f8 | 241 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 242 | type = "Major"; |
taptoneesarm | 0:5ddd4b0f64f8 | 243 | // ... a Major chord. |
taptoneesarm | 0:5ddd4b0f64f8 | 244 | } else if (list == 1) |
taptoneesarm | 0:5ddd4b0f64f8 | 245 | // ...if the chord comes from list '1', then it must be... |
taptoneesarm | 0:5ddd4b0f64f8 | 246 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 247 | type = "Minor"; |
taptoneesarm | 0:5ddd4b0f64f8 | 248 | // ... a Minor chord. |
taptoneesarm | 0:5ddd4b0f64f8 | 249 | } else if (list == 2) |
taptoneesarm | 0:5ddd4b0f64f8 | 250 | // ...if the chord comes from list '2', then it must be... |
taptoneesarm | 0:5ddd4b0f64f8 | 251 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 252 | type = "Sharp Major"; |
taptoneesarm | 0:5ddd4b0f64f8 | 253 | // ... a Sharp Major chord. |
taptoneesarm | 0:5ddd4b0f64f8 | 254 | } else if (list == 3) |
taptoneesarm | 0:5ddd4b0f64f8 | 255 | // ...if the chord comes from list '3', then it must be... |
taptoneesarm | 0:5ddd4b0f64f8 | 256 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 257 | type = "Sharp Minor"; |
taptoneesarm | 0:5ddd4b0f64f8 | 258 | // ... a Sharp Minor chord. |
taptoneesarm | 0:5ddd4b0f64f8 | 259 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 260 | |
taptoneesarm | 0:5ddd4b0f64f8 | 261 | position = 7*(list + 1) - shape; |
taptoneesarm | 0:5ddd4b0f64f8 | 262 | // Set the value of the 'position' as an indication of the position in the given list, |
taptoneesarm | 0:5ddd4b0f64f8 | 263 | // that is to say that higher chord values in the same list will have a lower |
taptoneesarm | 0:5ddd4b0f64f8 | 264 | // 'letter' due to the layout of the equation above. Irrespective of the list in |
taptoneesarm | 0:5ddd4b0f64f8 | 265 | // which it occurs... |
taptoneesarm | 0:5ddd4b0f64f8 | 266 | |
taptoneesarm | 0:5ddd4b0f64f8 | 267 | if (position == 1) |
taptoneesarm | 0:5ddd4b0f64f8 | 268 | // ...if the position value is 1, then it must be... |
taptoneesarm | 0:5ddd4b0f64f8 | 269 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 270 | letter = "G"; |
taptoneesarm | 0:5ddd4b0f64f8 | 271 | // ... a G chord. |
taptoneesarm | 0:5ddd4b0f64f8 | 272 | } else if (position == 2) |
taptoneesarm | 0:5ddd4b0f64f8 | 273 | // ...if the position value is 2, then it must be... |
taptoneesarm | 0:5ddd4b0f64f8 | 274 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 275 | letter = "F"; |
taptoneesarm | 0:5ddd4b0f64f8 | 276 | // ... an F chord. |
taptoneesarm | 0:5ddd4b0f64f8 | 277 | } else if (position == 3) |
taptoneesarm | 0:5ddd4b0f64f8 | 278 | // ...if the position value is 2, then it must be... |
taptoneesarm | 0:5ddd4b0f64f8 | 279 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 280 | letter = "E"; |
taptoneesarm | 0:5ddd4b0f64f8 | 281 | // ... an E chord. |
taptoneesarm | 0:5ddd4b0f64f8 | 282 | } else if (position == 4) |
taptoneesarm | 0:5ddd4b0f64f8 | 283 | // ...if the position value is 4, then it must be... |
taptoneesarm | 0:5ddd4b0f64f8 | 284 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 285 | letter = "D"; |
taptoneesarm | 0:5ddd4b0f64f8 | 286 | // ... a D chord. |
taptoneesarm | 0:5ddd4b0f64f8 | 287 | } else if (position == 5) |
taptoneesarm | 0:5ddd4b0f64f8 | 288 | // ...if the position value is 5, then it must be... |
taptoneesarm | 0:5ddd4b0f64f8 | 289 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 290 | letter = "C"; |
taptoneesarm | 0:5ddd4b0f64f8 | 291 | // ... a C chord. |
taptoneesarm | 0:5ddd4b0f64f8 | 292 | } else if (position == 6) |
taptoneesarm | 0:5ddd4b0f64f8 | 293 | // ...if the position value is 6, then it must be... |
taptoneesarm | 0:5ddd4b0f64f8 | 294 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 295 | letter = "B"; |
taptoneesarm | 0:5ddd4b0f64f8 | 296 | // ... a B chord. |
taptoneesarm | 0:5ddd4b0f64f8 | 297 | } else if (position == 7) |
taptoneesarm | 0:5ddd4b0f64f8 | 298 | // ...if the position value is 7, then it must be... |
taptoneesarm | 0:5ddd4b0f64f8 | 299 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 300 | letter = "A"; |
taptoneesarm | 0:5ddd4b0f64f8 | 301 | // ... an A chord. |
taptoneesarm | 0:5ddd4b0f64f8 | 302 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 303 | pc.printf("%s %s\n",letter,type.c_str()); |
taptoneesarm | 0:5ddd4b0f64f8 | 304 | // Output the letter of the chord, followed by its type separated by a |
taptoneesarm | 0:5ddd4b0f64f8 | 305 | // space such that the full name of the chord is displayed. |
taptoneesarm | 0:5ddd4b0f64f8 | 306 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 307 | |
taptoneesarm | 0:5ddd4b0f64f8 | 308 | //TODO fix return values |
taptoneesarm | 0:5ddd4b0f64f8 | 309 | //Change to a case/switch structure |
taptoneesarm | 0:5ddd4b0f64f8 | 310 | int shaper (int shape, int colour) |
taptoneesarm | 0:5ddd4b0f64f8 | 311 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 312 | if (shape == 0) |
taptoneesarm | 0:5ddd4b0f64f8 | 313 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 314 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 315 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 316 | illuminator (ledMapping(aMajor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 317 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 318 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 319 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 320 | else if (shape == 1) |
taptoneesarm | 0:5ddd4b0f64f8 | 321 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 322 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 323 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 324 | illuminator (ledMapping(bMajor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 325 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 326 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 327 | |
taptoneesarm | 0:5ddd4b0f64f8 | 328 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 329 | else if (shape == 2) |
taptoneesarm | 0:5ddd4b0f64f8 | 330 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 331 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 332 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 333 | illuminator (ledMapping(cMajor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 334 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 335 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 336 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 337 | else if (shape == 3) |
taptoneesarm | 0:5ddd4b0f64f8 | 338 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 339 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 340 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 341 | illuminator (ledMapping(dMajor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 342 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 343 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 344 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 345 | |
taptoneesarm | 0:5ddd4b0f64f8 | 346 | else if (shape == 4) |
taptoneesarm | 0:5ddd4b0f64f8 | 347 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 348 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 349 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 350 | illuminator (ledMapping(eMajor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 351 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 352 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 353 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 354 | else if (shape == 5) |
taptoneesarm | 0:5ddd4b0f64f8 | 355 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 356 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 357 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 358 | illuminator (ledMapping(fMajor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 359 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 360 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 361 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 362 | else if (shape == 6) |
taptoneesarm | 0:5ddd4b0f64f8 | 363 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 364 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 365 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 366 | illuminator (ledMapping(gMajor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 367 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 368 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 369 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 370 | else if (shape == 7) |
taptoneesarm | 0:5ddd4b0f64f8 | 371 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 372 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 373 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 374 | illuminator (ledMapping(aMinor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 375 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 376 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 377 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 378 | else if (shape == 8) |
taptoneesarm | 0:5ddd4b0f64f8 | 379 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 380 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 381 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 382 | illuminator (ledMapping(bMinor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 383 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 384 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 385 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 386 | else if (shape == 9) |
taptoneesarm | 0:5ddd4b0f64f8 | 387 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 388 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 389 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 390 | illuminator (ledMapping(cMinor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 391 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 392 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 393 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 394 | else if (shape == 10) |
taptoneesarm | 0:5ddd4b0f64f8 | 395 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 396 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 397 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 398 | illuminator (ledMapping(dMinor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 399 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 400 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 401 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 402 | else if (shape == 11) |
taptoneesarm | 0:5ddd4b0f64f8 | 403 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 404 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 405 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 406 | illuminator (ledMapping(eMinor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 407 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 408 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 409 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 410 | else if (shape == 12) |
taptoneesarm | 0:5ddd4b0f64f8 | 411 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 412 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 413 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 414 | illuminator (ledMapping(fMinor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 415 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 416 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 417 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 418 | else if (shape == 13) |
taptoneesarm | 0:5ddd4b0f64f8 | 419 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 420 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 421 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 422 | illuminator (ledMapping(gMinor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 423 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 424 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 425 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 426 | else if (shape == 14) |
taptoneesarm | 0:5ddd4b0f64f8 | 427 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 428 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 429 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 430 | illuminator (ledMapping(aSharpMajor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 431 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 432 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 433 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 434 | else if (shape == 16) |
taptoneesarm | 0:5ddd4b0f64f8 | 435 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 436 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 437 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 438 | illuminator (ledMapping(cSharpMajor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 439 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 440 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 441 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 442 | else if (shape == 19) |
taptoneesarm | 0:5ddd4b0f64f8 | 443 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 444 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 445 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 446 | illuminator(ledMapping(fSharpMajor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 447 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 448 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 449 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 450 | else if (shape == 20) |
taptoneesarm | 0:5ddd4b0f64f8 | 451 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 452 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 453 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 454 | illuminator(ledMapping(gSharpMajor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 455 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 456 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 457 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 458 | else if (shape == 21) |
taptoneesarm | 0:5ddd4b0f64f8 | 459 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 460 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 461 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 462 | illuminator(ledMapping(aSharpMinor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 463 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 464 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 465 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 466 | else if (shape == 26) |
taptoneesarm | 0:5ddd4b0f64f8 | 467 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 468 | for(int i = 0; i<6; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 469 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 470 | illuminator(ledMapping(fSharpMinor[i],i+1), colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 471 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 472 | feedback(colour); |
taptoneesarm | 0:5ddd4b0f64f8 | 473 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 474 | else |
taptoneesarm | 0:5ddd4b0f64f8 | 475 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 476 | //this point should never be reached; there are no other chords |
taptoneesarm | 0:5ddd4b0f64f8 | 477 | pc.printf ("Error: shaper failed\n"); |
taptoneesarm | 0:5ddd4b0f64f8 | 478 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 479 | // Send the colors to the LED strip. |
taptoneesarm | 0:5ddd4b0f64f8 | 480 | ledStrip.write(colors, LED_COUNT); |
taptoneesarm | 0:5ddd4b0f64f8 | 481 | if(colour == 1) |
taptoneesarm | 0:5ddd4b0f64f8 | 482 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 483 | wait(0.5); |
taptoneesarm | 0:5ddd4b0f64f8 | 484 | for(int i=0; i < LED_COUNT ; i++) |
taptoneesarm | 0:5ddd4b0f64f8 | 485 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 486 | colors[i] = (rgb_color){ 0, 0, 0 }; |
taptoneesarm | 0:5ddd4b0f64f8 | 487 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 488 | ledStrip.write(colors, LED_COUNT); |
taptoneesarm | 0:5ddd4b0f64f8 | 489 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 490 | |
taptoneesarm | 0:5ddd4b0f64f8 | 491 | return (0); |
taptoneesarm | 0:5ddd4b0f64f8 | 492 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 493 | |
taptoneesarm | 0:5ddd4b0f64f8 | 494 | int tester (int testChord, int requestChord) |
taptoneesarm | 0:5ddd4b0f64f8 | 495 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 496 | /* if (testChord == 0 || requestChord == 0) |
taptoneesarm | 0:5ddd4b0f64f8 | 497 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 498 | return (99); |
taptoneesarm | 0:5ddd4b0f64f8 | 499 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 500 | */ |
taptoneesarm | 0:5ddd4b0f64f8 | 501 | if (testChord == requestChord) |
taptoneesarm | 0:5ddd4b0f64f8 | 502 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 503 | return (1); |
taptoneesarm | 0:5ddd4b0f64f8 | 504 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 505 | else |
taptoneesarm | 0:5ddd4b0f64f8 | 506 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 507 | return (-1); |
taptoneesarm | 0:5ddd4b0f64f8 | 508 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 509 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 510 | |
taptoneesarm | 0:5ddd4b0f64f8 | 511 | int interpreter(int requestedCode) |
taptoneesarm | 0:5ddd4b0f64f8 | 512 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 513 | /* int r = 0; |
taptoneesarm | 0:5ddd4b0f64f8 | 514 | int chord = 0; |
taptoneesarm | 0:5ddd4b0f64f8 | 515 | |
taptoneesarm | 0:5ddd4b0f64f8 | 516 | r = rand() % 10; |
taptoneesarm | 0:5ddd4b0f64f8 | 517 | chord = rand() % 24; |
taptoneesarm | 0:5ddd4b0f64f8 | 518 | if(chord == 0) chord=1; |
taptoneesarm | 0:5ddd4b0f64f8 | 519 | |
taptoneesarm | 0:5ddd4b0f64f8 | 520 | if(r>1) return(requestedCode); |
taptoneesarm | 0:5ddd4b0f64f8 | 521 | else return(chord); */ |
taptoneesarm | 0:5ddd4b0f64f8 | 522 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 523 | |
taptoneesarm | 0:5ddd4b0f64f8 | 524 | |
taptoneesarm | 0:5ddd4b0f64f8 | 525 | int main() |
taptoneesarm | 0:5ddd4b0f64f8 | 526 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 527 | pc.baud (921600); |
taptoneesarm | 0:5ddd4b0f64f8 | 528 | string chord; |
taptoneesarm | 0:5ddd4b0f64f8 | 529 | char typed[20]; |
taptoneesarm | 0:5ddd4b0f64f8 | 530 | while(1) |
taptoneesarm | 0:5ddd4b0f64f8 | 531 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 532 | pc.printf("Type in the chord you would like to use \n"); |
taptoneesarm | 0:5ddd4b0f64f8 | 533 | pc.scanf("%s",typed); |
taptoneesarm | 0:5ddd4b0f64f8 | 534 | chordCode = decoder(typed); |
taptoneesarm | 0:5ddd4b0f64f8 | 535 | if (chordCode != -99 && chordCode != -1) |
taptoneesarm | 0:5ddd4b0f64f8 | 536 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 537 | identifier(chordCode); |
taptoneesarm | 0:5ddd4b0f64f8 | 538 | shaper(chordCode, 0); |
taptoneesarm | 0:5ddd4b0f64f8 | 539 | interpretedChordCode = interpreter(chordCode); |
taptoneesarm | 0:5ddd4b0f64f8 | 540 | testResult = tester(interpretedChordCode, chordCode); |
taptoneesarm | 0:5ddd4b0f64f8 | 541 | |
taptoneesarm | 0:5ddd4b0f64f8 | 542 | while(1) |
taptoneesarm | 0:5ddd4b0f64f8 | 543 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 544 | if(testResult == -1) |
taptoneesarm | 0:5ddd4b0f64f8 | 545 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 546 | wait(2); |
taptoneesarm | 0:5ddd4b0f64f8 | 547 | shaper(chordCode, testResult); |
taptoneesarm | 0:5ddd4b0f64f8 | 548 | wait(0.5); |
taptoneesarm | 0:5ddd4b0f64f8 | 549 | shaper(chordCode, 0); |
taptoneesarm | 0:5ddd4b0f64f8 | 550 | wait(1); |
taptoneesarm | 0:5ddd4b0f64f8 | 551 | interpretedChordCode = interpreter(chordCode); |
taptoneesarm | 0:5ddd4b0f64f8 | 552 | testResult = tester(interpretedChordCode, chordCode); |
taptoneesarm | 0:5ddd4b0f64f8 | 553 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 554 | else if(testResult == 1) |
taptoneesarm | 0:5ddd4b0f64f8 | 555 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 556 | wait(2); |
taptoneesarm | 0:5ddd4b0f64f8 | 557 | shaper(chordCode, testResult); |
taptoneesarm | 0:5ddd4b0f64f8 | 558 | wait(0.5); |
taptoneesarm | 0:5ddd4b0f64f8 | 559 | break; |
taptoneesarm | 0:5ddd4b0f64f8 | 560 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 561 | else if(testResult == 99) |
taptoneesarm | 0:5ddd4b0f64f8 | 562 | { |
taptoneesarm | 0:5ddd4b0f64f8 | 563 | pc.printf("Error"); |
taptoneesarm | 0:5ddd4b0f64f8 | 564 | break; |
taptoneesarm | 0:5ddd4b0f64f8 | 565 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 566 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 567 | wait_ms(10); |
taptoneesarm | 0:5ddd4b0f64f8 | 568 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 569 | } |
taptoneesarm | 0:5ddd4b0f64f8 | 570 | } |