:)

Dependencies:   MbedJSONValue DebounceIn TextLCD USBDevice mbed WebSocketClient cc3000_hostdriver_mbedsocket Adafruit_LEDBackpack_2

Files at this revision

API Documentation at this revision

Comitter:
fil
Date:
Tue Nov 25 23:56:23 2014 +0000
Parent:
5:03d75ad40d5e
Child:
7:7fbe8dc5e4fa
Commit message:
Included 24x2 to multiplexer address decoding.

Changed in this revision

Adafruit_LEDBackpack_2.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Adafruit_LEDBackpack_2.lib	Mon Nov 24 17:52:11 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/ddrew73/code/Adafruit_LEDBackpack_2/#0491b3f9a639
--- a/main.cpp	Mon Nov 24 17:52:11 2014 +0000
+++ b/main.cpp	Tue Nov 25 23:56:23 2014 +0000
@@ -28,6 +28,9 @@
 DigitalOut A_in(D0);
 DigitalOut B_in(D1);
 DigitalOut C_in(D2);
+DigitalOut D_in(D3);
+DigitalOut E_in(D4);
+DigitalOut F_in(D5);
 
 DigitalOut A_out(PTC7);
 DigitalOut B_out(PTC0);
@@ -145,7 +148,9 @@
         //Implementing scanning
 
         if (scanbutton.read() == 0) {
-
+            
+            // Old mega-scan code. More refined version below
+            /*
             for (int x = 0; x < 8; x++) {
                 for (int y = 0; y < 8; y++) {
                     // Stupid logic to convert count value to binary...
@@ -177,8 +182,7 @@
                     //keyboard.printf("%d %d %d\n",a2,b2,c2);
                 }
             }
-
-            /*
+            
             for (int x=0;x<8;x++) {
             for (int y=0;y<8;y++) {
                 keyboard.printf("%d ",con_mat[x][y]);
@@ -223,64 +227,78 @@
 //Scans rows connected to vdd and ground. Vdd = 2 in con mat, Ground = 3. Rows connected to selected row = 1.
 
 //SET MULTIPLEXER TO READ VDD
-vddval = adc.read();
+            for (int i=0; i++; i<2) {
+                for (int j=0; j++; i<24) {
+                    
+                    float test_val = adc.read();
+                    if (test_val == 0.0) {
+                        // this node is ground...
+                    }
+                    else if ((test_val > vdd_samp-0.01) && (test_val < vdd_samp+0.01)) {
+                        // this node is VDD
+                    }
+                    else if ((test_val > select_val-0.01) && (test_val < select_val+0.01)) {
+                        // this node is connected to the selected node
+                    }
+                    else {
+                        // this node is floating?
+                    }
+                }
+            }
+            
+A_in,B_in,C_in,D_in,E_in,F_in = 1;
+float vddval = adc.read();
 
 //SET MULTIPLEXER TO READ SELECTED ROW
-rowval = adc.read();
+// Sample the 'selected' node
+int sn = 0;
+int sn = (colselect + 1)*(rowselect + 1);
+A_in = (sn-1)&2; B_in = ((sn-1)/2)%2; C_in = ((sn-1)/4)%2; D_in = ((sn-1)/8)%2; E_in = ((sn-1)/16)%2; F_in = ((sn-1)/32)%2;
+float rowval = adc.read();
 
 ledbar_left.clear();
 ledbar_right.clear();
 
 for (int x = 0; x < 2; x++) {
         for (int y = 0; y < 24; y++) {
-        A_in = x%2;
-        a1 = x%2;
-        B_in = (x/2)%2;
-        b1 = (x/2)%2;
-        C_in = (x/4)%2;
-        c1 = (x/4)%2;
+            int sn = (colselect+1)*(rowselect+1);
+            A_in = (sn-1)&2; B_in = ((sn-1)/2)%2; C_in = ((sn-1)/4)%2; D_in = ((sn-1)/8)%2; E_in = ((sn-1)/16)%2; F_in = ((sn-1)/32)%2;
+
+            float in_val = adc.read();
+            volt_mat[x][y] = in_val;
 
-        A_out = y%2;
-        int a2 = y%2;
-        B_out = (y/2)%2;
-        b2 = (y/2)%2;
-        C_out = (y/4)%2;
-        c2 = (y/4)%2;
-
-        float in_val = adc.read();
-        volt_mat[x][y] = in_val;
-
-        if (in_val == vddval){
-            con_mat[x][y] = 2;
-            if (x == 0){
-                ledbar_left.setBar(y,LED_RED);
+            if (in_val == vddval){
+                con_mat[x][y] = 2;
+                if (x == 0){
+                    ledbar_left.setBar(y,LED_RED);
+                }
+                else {
+                    ledbar_right.setBar(y,LED_RED);
+                }
+            }
+            if (in_val == 0){
+                con_mat[x][y] = 3;
+                if (x == 0){
+                    ledbar_left.setBar(y,LED_YELLOW);
+                }
+                else {
+                    ledbar_right.setBar(y,LED_YELLOW);
+                }
+            }
+            if (in_val == rowval){
+                con_mat[x][y] = 1;
+                if (x == 0){
+                    ledbar_left.setBar(y,LED_GREEN);
+                }
+                else {
+                    ledbar_right.setBar(y,LED_GREEN);
+                }
             }
             else {
-                ledbar_right.setBar(y,LED_RED);
-            }
-            }
-        if (in_val == 0){
-            con_mat[x][y] = 3;
-            if (x == 0){
-            ledbar_left.setBar(y,LED_YELLOW);
-            }
-            else {
-            ledbar_right.setBar(y,LED_YELLOW);
-            }
+                con_mat[x][y] = 0;
             }
-        if (in_val == rowval){
-            con_mat[x][y] = 1;
-            if (x == 0){
-                ledbar_left.setBar(y,LED_GREEN);
-            }
-            else {
-                ledbar_right.setBar(y,LED_GREEN);
-            }
-            }
-        else
-            con_mat[x][y] = 0;
         }
-        }
+        
 moved = 0;
 
 //// PUT ALL ABOVE IN SCAN BUTTON IF /////