:)
Dependencies: MbedJSONValue DebounceIn TextLCD USBDevice mbed WebSocketClient cc3000_hostdriver_mbedsocket Adafruit_LEDBackpack_2
Revision 7:7fbe8dc5e4fa, committed 2014-11-26
- Comitter:
- ddrew73
- Date:
- Wed Nov 26 00:39:46 2014 +0000
- Parent:
- 6:d0a1eba7f943
- Child:
- 8:725d938b301b
- Commit message:
- CompElation!;
Changed in this revision
Adafruit_LEDBackpack_2.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Adafruit_LEDBackpack_2.lib Wed Nov 26 00:39:46 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/ddrew73/code/Adafruit_LEDBackpack_2/#0491b3f9a639
--- a/main.cpp Tue Nov 25 23:56:23 2014 +0000 +++ b/main.cpp Wed Nov 26 00:39:46 2014 +0000 @@ -10,16 +10,16 @@ #include "MbedJSONValue.h" //LED stuff -I2C i2c(D7,D6); -Adafruit_24bargraph ledbar_left=Adafruit_24bargraph(&i2c); +I2C i2c_left(D7,D6); +Adafruit_24bargraph ledbar_left=Adafruit_24bargraph(&i2c_left); -I2C i2c(D7,D6); -Adafruit_24bargraph ledbar_right=Adafruit_24bargraph(&i2c); +I2C i2c_right(D5,D4); +Adafruit_24bargraph ledbar_right=Adafruit_24bargraph(&i2c_right); DebounceIn upbutton(D9); DebounceIn downbutton(D8); -DebounceIn leftbutton( ); -DebounceIn rightbutton( ); +DebounceIn leftbutton(D3); +DebounceIn rightbutton(D2); //Scanner stuff @@ -59,21 +59,23 @@ "SSID", "PASSWORD", WPA2, false); Websocket ws("ws://sockets.mbed.org/ws/toastboard/rw"); +MbedJSONValue demo; + int main() { //Scan init - - float test_val = .001; - float row_volt = 0; + int con_mat[24][2] = {}; - int a1,b1,c1,a2,b2,c2; float volt_mat[24][2] = {}; + float clientdata[48] = {}; + float rowval = 0, vddval = 0; + //dac = test_val; //LED init - int redcount = 0, greencount = 0, rowselect = 0, rowselect_old = 0, moved = 1, colselect = 0; + int rowselect = 0, moved = 1, colselect = 0, selected = 0; ledbar_left.begin(0x70); ledbar_left.clear(); ledbar_left.writeDisplay(); @@ -84,9 +86,7 @@ //LCD init lcd.cls(); - string programname = "Dan's UI Test"; - lcd.printf("%s",programname.c_str()); while(1) { @@ -98,23 +98,24 @@ ledbar_left.setBar(rowselect,LED_GREEN); ledbar_left.writeDisplay(); ledbar_right.writeDisplay(); - } else - ledbar_left.clear(); + } + else { + ledbar_left.clear(); ledbar_right.clear(); ledbar_right.setBar(rowselect,LED_GREEN); ledbar_right.writeDisplay(); ledbar_left.writeDisplay(); - + } //Moving the selected row if (upbutton.read() == 0) { - rowselect_old = rowselect; + rowselect = rowselect-1; moved = 1; wait(0.75); } if (downbutton.read() == 0) { - rowselect_old = rowselect; + rowselect = rowselect+1; moved = 1; wait(0.75); @@ -125,7 +126,7 @@ ledbar_right.clear(); moved =1; wait(0.75); - + } if (rightbutton.read() == 0) { @@ -133,8 +134,8 @@ ledbar_left.clear(); moved =1; wait(0.75); - - + + } //Boundary checking @@ -148,193 +149,145 @@ //Implementing scanning if (scanbutton.read() == 0) { + A_in = 1; + B_in = 1; + C_in = 1; + D_in = 1; + E_in = 1; + F_in = 1; - // 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... - 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; + vddval = adc.read(); - 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; - - // Now we do the scan test, results are stored in con_mat - //wait(0.01); - dac = test_val; - float in_val = adc.read(); - - if ((in_val > .0010) && (in_val < .0025)) - con_mat[x][y] = 1; - else - con_mat[x][y] = 0; - - //keyboard.printf("%f %f \n",dac.read(),in_val); - //keyboard.printf("%d %d %d\n",a2,b2,c2); - } - } + //SET MULTIPLEXER TO READ SELECTED ROW + // Sample the 'selected' node - for (int x=0;x<8;x++) { - for (int y=0;y<8;y++) { - keyboard.printf("%d ",con_mat[x][y]); - }} - */ - //Displaying all connected rows as red light! - ledbar.clear(); - for (int i=0; i<8; i++) { - if (con_mat[rowselect][i] == 1) { - ledbar.setBar(i,LED_RED); - } - } - ledbar.writeDisplay(); + 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; + rowval = adc.read(); - float vddmeasure = 3.14259; - float vrowmeasure = 1.1234; - lcd.cls(); - lcd.locate(0,1); - lcd.printf("Vdd: %1.1f V",vddmeasure); - lcd.locate(0,0); - lcd.printf("Row: %1.1f V",vrowmeasure); + ledbar_left.clear(); + ledbar_right.clear(); - wait(2.5); - ledbar.clear(); - ledbar.writeDisplay(); - lcd.cls(); - string programname = "Dan's UI Test"; - lcd.printf("%s",programname.c_str()); - - } - } - - - - -} - + for (int x = 0; x < 2; x++) { + for (int y = 0; y < 24; y++) { + 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; -/* - -///// PUT ALL BELOW IN SCAN BUTTON IF //////// -//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 - for (int i=0; i++; i<2) { - for (int j=0; j++; i<24) { + float in_val = adc.read(); + volt_mat[x][y] = in_val; - 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 + if (x == 1){ + int z = y+24; + clientdata[z] = in_val; } else { - // this node is floating? + clientdata[y] = in_val; + } + + + if ((in_val > vddval-0.01) && (in_val < vddval+0.01)) { + con_mat[x][y] = 2; + if (x == 0) { + ledbar_left.setBar(y,LED_RED); + } else { + ledbar_right.setBar(y,LED_RED); + } + } + else 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); + } + } + else if ((in_val > rowval-0.01) && (in_val < rowval+0.01)) { + 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; } - } - } - -A_in,B_in,C_in,D_in,E_in,F_in = 1; -float vddval = adc.read(); - -//SET MULTIPLEXER TO READ SELECTED ROW -// 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++) { - 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; - - 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); - } + + + } } //END OF ROWSCAN FOR LOOP + + //STUFF INTO JSON FORMAT + char str[1]; + for (int i= 0; i < 48; i++) { + sprintf(str, "%d", i); + demo[str] = clientdata[i]; + } + demo["vdd"] = vddval; + demo["rowval"] = rowval; + selected = rowselect; + if (colselect == 1){ + selected = selected+24; + } + demo["selected"] = selected; + + + + moved = 0; + + wait(2); //THIS NEEDS TO GO AWAY! :} + + } // END OF SCANBUTTON IF STATEMENT + + if (moved==0) { + ledbar_left.writeDisplay(); + ledbar_right.writeDisplay(); + lcd.cls(); + lcd.locate(0,1); + lcd.printf("Vdd: %1.1f V",vddval); + lcd.locate(0,0); + lcd.printf("Row %d: %1.1f V",selected,rowval); + } 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 { - con_mat[x][y] = 0; - } - } - -moved = 0; - -//// PUT ALL ABOVE IN SCAN BUTTON IF ///// - - - -if (moved==0) { -ledbar_left.writeDisplay(); -ledbar_right.writeDisplay(); -lcd.cls(); -lcd.locate(0,1); -lcd.printf("Vdd: %1.1f V",vddval); -lcd.locate(0,0); -lcd.printf("Row: %1.1f V",rowval); -} -else { - lcd.cls(); - string programname = "Dan's UI Test"; - string instructions = "Select a row and scan it"; - lcd.locate(0,0); - lcd.printf("%s",programname.c_str()); - lcd.locate(0,1); - lcd.printf("%s",instructions.c_str()); -} + lcd.cls(); + string programname = "The ToastBoard"; + string instructions = "Select a row and scan"; + lcd.locate(0,0); + lcd.printf("%s",programname.c_str()); + lcd.locate(0,1); + lcd.printf("%s",instructions.c_str()); + } -//Q: Do we need to do the same test for ground or can 0.00 be assumed? -//Q: What is the most efficient way to compare all the "volt_mat" elements? -//Q: Do we need to add a "confidence interval" around the rowval and vdd tests? + + + -*/ + } // END OF WHILE(1) + + + + } // END OF INT MAIN + + + + + +