:)
Dependencies: MbedJSONValue DebounceIn TextLCD USBDevice mbed WebSocketClient cc3000_hostdriver_mbedsocket Adafruit_LEDBackpack_2
Revision 21:4ec999be140a, committed 2014-12-11
- Comitter:
- jn80842
- Date:
- Thu Dec 11 19:15:20 2014 +0000
- Parent:
- 20:b30b958dbd86
- Commit message:
- dan/filip's changes to handle floating rows
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Dec 11 03:08:30 2014 +0000 +++ b/main.cpp Thu Dec 11 19:15:20 2014 +0000 @@ -35,8 +35,8 @@ //Scanner stuff -//DebounceIn scanbutton(PTC13); -DebounceIn scanbutton(D7); +DebounceIn scanbutton(PTC13); +//DebounceIn scanbutton(D7); DigitalOut A_in(PTB10); DigitalOut B_in(PTB11); @@ -67,9 +67,9 @@ void lcd_write_voltage_info(float vddval,int selected,float rowval) { lcd.cls(); lcd.locate(0,1); - lcd.printf("Vdd: %1.1f V",vddval); + lcd.printf("Vdd: %1.2f V",vddval); lcd.locate(0,0); - lcd.printf("Row %d: %1.1f V",selected,rowval); + lcd.printf("Row %d: %1.2f V",selected,rowval); } @@ -140,11 +140,13 @@ } + bool voltages_equal(float voltage1,float voltage2) { - return (voltage1 > voltage2-0.008) && (voltage1 < voltage2+0.008); + return (voltage1 > voltage2-0.005) && (voltage1 < voltage2+0.005); } void read_voltages(float voltages[48]) { + float voltbuffer[48] = {}; scan_select = 0; int sn = 0; for (int i=0;i<48;i++) { @@ -155,9 +157,12 @@ A_in = ((sn)/8)%2; B_in = ((sn)/16)%2; C_in = ((sn)/32)%2; - - voltages[sn] = adc.read(); - + + for (int j=0;j<10;j++) { + wait(0.0025); + voltbuffer[sn] = (adc.read()/10) + voltbuffer[sn]; + } + voltages[sn] = voltbuffer[sn]; } } @@ -187,7 +192,7 @@ in_val = adc.read(); - if ((in_val < voltages[sn]-0.0008) || (in_val > voltages[sn]+0.0008)){ + if ((in_val < voltages[sn]-0.008) || (in_val > voltages[sn]+0.008)){ voltages[sn] = 100.0; } @@ -198,8 +203,9 @@ -void compare_voltages(float voltages[48], float clientdata[48], int colselect, int rowselect, float vddval, float floatchecked[48]) { +void compare_voltages(float voltages[48], float clientdata[48], int colselect, int rowselect, float vddval, float floatchecked[48], float newvoltages[48]) { // get selected row voltage + float voltbuffer[48] = {}; scan_select = 0; float rowval = voltages[(colselect*24)+ rowselect]; for (int i=0;i<48;i++) { @@ -210,8 +216,15 @@ A_in = ((sn)/8)%2; B_in = ((sn)/16)%2; C_in = ((sn)/32)%2; - - float in_val = adc.read(); + + for (int j=0;j<10;j++) { + wait(0.0025); + voltbuffer[sn] = (adc.read()/10) + voltbuffer[sn]; + } + newvoltages[sn] = voltbuffer[sn]; + + // float in_val = adc.read(); + // newvoltages[i] = in_val; if (floatchecked[sn] == 100){ set_led(i,LED_OFF); @@ -219,19 +232,20 @@ } else { - if (!voltages_equal(voltages[i],in_val)) { + + if (!voltages_equal(voltages[i],newvoltages[sn])) { // this row is floating set_led(i,LED_OFF); clientdata[i] = 100.0; - } else if (voltages_equal(voltages[i],vddval)) { + } else if (voltages_equal(voltages[i],vddval) || voltages_equal(newvoltages[i],vddval)) { // this row matches vdd set_led(i,LED_RED); clientdata[i] = vddval; - } else if (voltages_equal(voltages[i],0.0)) { + } else if (voltages_equal(voltages[i],0.0) || voltages_equal(newvoltages[i],0.0)) { // this row matches ground set_led(i,LED_YELLOW); clientdata[i] = 0.0; - } else if (voltages_equal(voltages[i],rowval)) { + } else if (voltages_equal(voltages[i],rowval) || voltages_equal(newvoltages[i],rowval)) { // this row matches selected row set_led(i,LED_GREEN); clientdata[i] = rowval; @@ -249,6 +263,8 @@ //Scan init float originalvoltages[48] = {}; + float newvoltages[48] = {}; + float clientdata[48] = {}; float vddval = 0.0; float rowval = 0.0; @@ -272,7 +288,6 @@ wifi.init(); char * writable; - // Websocket ws("ws://sockets.mbed.org/ws/toastboard/rw"); //Osci int loopcount = 0, pressed = 0; @@ -284,7 +299,7 @@ while(1) { if (wifi.is_connected() == false) { - pc.printf("trying to connect to wifi\r\n"); + pc.printf("trying to connect to v\r\n"); if (wifi.connect() == -1) { pc.printf("Failed to connect\r\n"); } else { @@ -304,7 +319,7 @@ } - + //Display if (moved ==1) { @@ -363,6 +378,12 @@ //Implementing scanning if (scanbutton.read() == 0) { + + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Scanning...."); + + float vddbuff = 0; A_in = 0; B_in = 1; C_in = 1; @@ -370,19 +391,26 @@ E_in = 0; F_in = 0; - vddval = adc.read(); + for (int j=0;j<10;j++) { + wait(0.0025); + vddbuff = (adc.read()/10) + vddbuff; + } + vddval = vddbuff; + + + ledbar_left.clear(); ledbar_right.clear(); // first set of voltages read into old_volt_mat - float_check(floatout,dacval); + + //float_check(floatout,dacval); wait(0.2); read_voltages(originalvoltages); - // second set for comparison, read into clientdata wait(0.2); - compare_voltages(originalvoltages,clientdata,colselect,rowselect,vddval,floatout); + compare_voltages(originalvoltages,clientdata,colselect,rowselect,vddval,floatout,newvoltages); @@ -396,11 +424,11 @@ pc.printf("\r\n%1.3f %1.3f \r\n", vddval, rowval); for (int i = 0; i<48; i++) { - pc.printf(" %1.3f ", clientdata[i]); + pc.printf(" %1.4f ", clientdata[i]); } pc.printf(" \r\n \r\n "); for (int x = 0; x < 48; x++) { - pc.printf("%1.4f %1.4f %d \r\n", originalvoltages[x], floatout[x], x+1); + pc.printf("%1.4f %1.4f %d \r\n", originalvoltages[x], newvoltages[x], x+1); } //////////////////////// @@ -425,6 +453,8 @@ pc.printf(writable); pc.printf("\r\n"); + + written = 1; } else if (oldselected != selected) { lcd_write_selected_info(selected);