Solo project mbed 2

Dependencies:   PololuLedStrip mbed

Fork of SX10_BigBangFinal_A by Tapton Eesarm

Revision:
1:e4d11295b3f4
Parent:
0:5ddd4b0f64f8
Child:
2:bc7345c92188
--- a/main.cpp	Thu Jan 26 11:00:15 2017 +0000
+++ b/main.cpp	Mon Jan 30 13:10:56 2017 +0000
@@ -5,6 +5,14 @@
 #define LED_COUNT 60
 
 Serial pc(USBTX, USBRX); // tx, rx
+Serial device(p13, p14);  // tx, rx to connect to mbed 1
+
+DigitalOut ledd1(LED1);
+DigitalOut ledd2(LED2);
+DigitalOut ledd3(LED3);
+DigitalOut ledd4(LED4);
+
+char rx_buffer[10]; //Only small as not an interupt buffer
 
 PololuLedStrip ledStrip(p11);
 
@@ -94,47 +102,49 @@
         // If its hexadecimal number corresponds to a uppercase letter
         // such that it is a major chord and...
         {
-            if (typed.size() == 1)
+          //  if (typed.size() == 1)
             // ...if the input is only one letter/symbol...
-            {
-                chordValue = ascii - 65;
+          //  {
+                chordValue = ascii - 65; // Just set the chord as non sharp
+                
                 // ...then offset the hexadecimal code of that letter by 65
                 // to map it back to the original list of non-sharp major chords and
                 // store that value.
-            }
-            else
+          //  }
+          //  else
             // ...if the input is more than one letter/symbol then assume
             // a hash (#) was entered to indicate a sharp value so...
-            {
+          /*  {
                 chordValue = ascii - 51;
                 // ...offset the hexadecimal code by 51 to map it back to
                 // the original list of sharp major chords and store that value.
             }
+          */
         }
         else if (97 <= ascii && ascii <= 103)
         // If its hexadecimal number corresponds to a lowercase letter
         // such that it is a minor chord and...
         {
-            if (typed.size() == 1)
+          //  if (typed.size() == 1)
             // ...if the input is only one letter/symbol...
-            {
+          //  {
                 chordValue = ascii - 90;
                 // ...then offset the hexadecimal code by 90 to map it back to
                 // the original list of non-sharp minor chords and store that value.
-            }
-            else
+           // }
+          //  else
             // ...if the input is more than one letter/symbol then assume
             // a hash (#) was entered to indicate a sharp value so...
-            {
-                chordValue = ascii - 76;
+          //  {
+           //     chordValue = ascii - 76;
                 // ...offset the hexadecimal code by 51 to map it back to
                 // the original list of sharp minor chords and store that value.
-            }
+          //  }
         } 
         else
         // If the typed character does not correspond to an existing chord then...
         {
-            pc.printf("Incorrect input\n");
+            pc.printf("Incorrect input");
             // Output an error message that indicates an incorrect input by the
             // user and...
             return(-99);
@@ -142,7 +152,7 @@
             // the code.
         }
         
-        if (typed.size() > 2)
+   /*     if (typed.size() > 2)
         // If the user input is greater than two characters then...
         {
             pc.printf("Incorrect input\n");
@@ -152,7 +162,7 @@
             // ...output -99 to indicate an error has occured to other parts of
             // the code. 
         }
-        
+  */      
         if (chordValue != 15 && chordValue != 17 && chordValue != 18 && chordValue != 22 && chordValue != 23 && chordValue != 24 && chordValue != 25 && chordValue != 27)
         // If the obtained chord value corresponds to a chord that can actually be
         // played by Solo then...
@@ -177,15 +187,15 @@
      //pc.printf ("Position: %d Colour: %d\n",position,colour);
      if (position != -1)
      {
-         if (colour == -1)
+         if (colour == -1) //out of tune
          {
             colors[position] = (rgb_color){40,0,0};
          }
-         else if (colour == 0)
+         else if (colour == 0) // processing
          {
             colors[position] = (rgb_color){40,40,40};
          }
-         else if (colour == 1)
+         else if (colour == 1) //in tune
          {
             colors[position] = (rgb_color){0,40,0};
          }
@@ -508,9 +518,10 @@
     }
 }
 
-int interpreter(int requestedCode)
+
+/*int interpreter(int requestedCode)// this function was all commented out
 {
-/*   int r = 0;
+   int r = 0;
     int chord = 0;
  
     r = rand() % 10;
@@ -518,48 +529,80 @@
     if(chord == 0) chord=1;
         
     if(r>1) return(requestedCode);
-    else return(chord); */    
+    else return(chord);     
+
 }
-
+*/
 
 int main()
 {
-    pc.baud (921600);
+    pc.baud (19200);
+    device.baud(19200); //for communications with mbed 1
     string chord;
     char typed[20];
     while(1)
     {
-        pc.printf("Type in the chord you would like to use \n");
-        pc.scanf("%s",typed);
+   //     pc.printf("Type in the chord you would like to use \n");
+   //     pc.scanf("%s",typed);
+   ledd1=0;
+   ledd2=0;
+   ledd3=0;
+   ledd4=0;
+    if (device.readable()){
+        //ledd1=1;
+        char som = device.getc();
+        if (som == 'Q'){ //Is the received byte a SOM (letter Q)?
+        for (int j=0; j<=6; j++) {  //if it is a SOM get the next 6 bytes from serial port
+            if (device.readable()){
+                //rx_buffer[j] = device.getc();
+                //pc.printf("%d%s", j,rx_buffer[j]);
+                som = device.getc();
+                if (j==1) { //get byte 3 (key/note) from serial port message
+                        typed[0] = som; // put the key /note into the typed array 
+                        pc.putc(typed[0]); //print it to a pc on the USB
+                        }
+                //pc.putc(device.getc());
+                //pc.printf("%d",j);
+          //      ledd2=1;
+                wait(0.1);
+                }
+                }
+                }
+            //    ledd3=1;
+            }
         chordCode = decoder(typed);
         if (chordCode != -99 && chordCode != -1)
         {
+            ledd1=1;
             identifier(chordCode);
             shaper(chordCode, 0);
-            interpretedChordCode = interpreter(chordCode);
+            interpretedChordCode = chordCode; // removed interpreter(chordCode);
             testResult = tester(interpretedChordCode, chordCode);
-        
+    
             while(1)
             {
                 if(testResult == -1)
                 {
+                   ledd2=1;
                    wait(2);
                    shaper(chordCode, testResult);
                    wait(0.5);
                    shaper(chordCode, 0);
                    wait(1);
-                   interpretedChordCode = interpreter(chordCode);
+                   interpretedChordCode = chordCode; // removed interpreter(chordCode);
                    testResult = tester(interpretedChordCode, chordCode);
                 }
                 else if(testResult == 1)
                 {
-                   wait(2);
+                   ledd3=1;
+                   wait(2); 
                    shaper(chordCode, testResult);
                    wait(0.5);
                    break;
                 }
                 else if(testResult == 99)
                 {
+                    ledd4=1;
                     pc.printf("Error");
                     break;
                 }