Abel Zatarain / Mbed 2 deprecated FMSynthCSUSM

Dependencies:   mbed

Revision:
8:13b0594510de
Parent:
7:b0cd74923bc6
Child:
9:86c0035f5321
--- a/main.cpp	Wed Dec 06 22:33:04 2017 +0000
+++ b/main.cpp	Thu Dec 07 02:09:10 2017 +0000
@@ -21,11 +21,14 @@
 AnalogIn ADC14(PC_4);
 AnalogIn ADC15(PC_5);
 
-BusIn keyBank(PC_10, PC_11, PC_12, PC_13, PC_14, PC_15);
+//BusIn keyBank(PC_10, PC_11, PC_12, PC_13, PD_2, PH_1); old
+BusIn keyBank(PH_1, PD_2, PC_13, PC_12, PC_11, PC_10);
 BusOut bankSelect(PB_0, PB_1, PB_2, PB_3, PB_4, PB_5, PB_6, PB_7, PB_8);
 BusIn numerator(PA_8, PA_9, PA_10, PA_11);
 BusIn denominator(PA_12, PA_13, PA_14, PA_15);
 
+Serial pc(USBTX, USBRX);
+
 //Renaming ports
 #define inVol ADC0
 //#define inModAmt ADC1
@@ -185,6 +188,8 @@
     int ratNumer;
     int ratDenom;
     
+    keyBank.mode(PullNone);
+    
     while(true){
         ratNumer = 0xf & ~ numerator;
         ratDenom = 0xf & ~ denominator;
@@ -216,13 +221,19 @@
         //'keyboard' should be uint64_t and not int64_t b/c keyboard&=~62 will make it negative, which isn't a huge deal really
         keyboard = 0; //zero the keys before we start ORing on top of everything
         for(int i = 0; i < 9; ++i) { //removed <= 9 because there is not 10 banks
-            bankSelect = (short)(~(1 << i)) & bankSelect.mask();
+            bankSelect = (~(1LL << i)) & (unsigned long long)bankSelect.mask();
+            wait_us(200);
+            int shiftOffset = 6LL * i;
+            //shiftOffset -= 5; //bank 0 only has 1 key, so to prevent 5 missing keys and bits we subtract 5 for every bank > 0
+            //else keyboard &= ~31; //clear bits 1-5 (xx00000x) b/c we are ORing the next bank of keys on top of them & they may not be 0
     
-            int shiftOffset = 6 * i;
-            if(i > 0) shiftOffset -= 5; //bank 0 only has 1 key, so to prevent 5 missing keys and bits we subtract 5 for every bank > 0
-            else keyboard &= ~62; //clear bits 1-5 (xx00000x) b/c we are ORing the next bank of keys on top of them & they may not be 0
-    
-            keyboard |= ((~keyBank) & keyBank.mask()) << shiftOffset;
+            keyboard |= ((~(unsigned long long)keyBank) & (unsigned long long)keyBank.mask()) << (unsigned long long)shiftOffset;
         }
+        keyboard >>= 5;
+        /*for(int i = 63; i >= 0; i--) {
+            pc.printf("%d", !!(keyboard & (1LL << i)));
+        }
+        pc.printf("\r\n");
+        wait_ms(200);*/
     }
 }