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