:)
Dependencies: MbedJSONValue DebounceIn TextLCD USBDevice mbed WebSocketClient cc3000_hostdriver_mbedsocket Adafruit_LEDBackpack_2
Diff: main.cpp
- Revision:
- 16:028a8548ab22
- Parent:
- 15:236d90e38951
- Child:
- 17:fcc378db08f4
diff -r 236d90e38951 -r 028a8548ab22 main.cpp --- a/main.cpp Tue Dec 09 18:21:26 2014 +0000 +++ b/main.cpp Tue Dec 09 20:06:17 2014 +0000 @@ -44,8 +44,10 @@ DigitalOut E_in(PTE4); DigitalOut F_in(PTE5); +DigitalOut scan_select(PTC3); + AnalogIn adc(PTB0); - +AnalogOut dac(PTE30); @@ -141,10 +143,11 @@ } void read_voltages(float voltages[48]) { + scan_select = 0; int sn = 0; for (int i=0;i<48;i++) { // iterate over two columns of breadboard // iterate over 24 rows of each column - sn = i; // maybe????? + sn = i; D_in = (sn)%2; E_in = ((sn)/2)%2; F_in = ((sn)/4)%2; @@ -157,8 +160,46 @@ } } -void compare_voltages(float voltages[48], float clientdata[48], int colselect, int rowselect, float vddval) { +void float_check(float voltages[48],float dacval) { + int sn = 0; + for (int i=0;i<48;i++) { // iterate over two columns of breadboard + // iterate over 24 rows of each column + sn = i; + D_in = (sn)%2; + E_in = ((sn)/2)%2; + F_in = ((sn)/4)%2; + A_in = ((sn)/8)%2; + B_in = ((sn)/16)%2; + C_in = ((sn)/32)%2; + + scan_select = 1; + scan_select = 0; + wait(0.01); + float in_val = adc.read(); + voltages[sn] = in_val; + + wait(0.01); + + scan_select = 1; + scan_select = 0; + wait(0.01); + in_val = adc.read(); + + + if ((in_val < voltages[sn]-0.004) || (in_val > voltages[sn]+0.004)){ + voltages[sn] = 100; + + } + + + } +} + + + +void compare_voltages(float voltages[48], float clientdata[48], int colselect, int rowselect, float vddval, float floatchecked[48]) { // get selected row voltage + scan_select = 0; float rowval = voltages[(colselect*24)+ rowselect]; for (int i=0;i<48;i++) { int client_index = (colselect*24)+rowselect; @@ -172,6 +213,11 @@ float in_val = adc.read(); + if (floatchecked[sn] == 100){ + set_led(i,LED_OFF); + clientdata[client_index] = 100.0; + } + else { if (!voltages_equal(voltages[i],in_val)) { // this row is floating @@ -193,8 +239,9 @@ set_led(i,LED_OFF); clientdata[client_index] = voltages[i]; } - } -} + } // else if closing + } //for loop closing + } //compare_voltages function closing int main() @@ -206,6 +253,10 @@ float clientdata[48] = {}; float vddval = 0.0; float rowval = 0.0; + float dacval = 0.1; + + float floatout[48] = {}; + float floatoutsecond[48] = {}; //LED init int rowselect = 0, moved = 1, colselect = 0, selected = 0, oldselected = 49; @@ -311,11 +362,14 @@ // first set of voltages read into old_volt_mat read_voltages(originalvoltages); - wait(0.2); + wait(0.4); read_voltages(newvoltages); // second set for comparison, read into clientdata + wait(0.4); + compare_voltages(originalvoltages,clientdata,colselect,rowselect,vddval,floatout); + wait(0.2); - compare_voltages(originalvoltages,clientdata,colselect,rowselect,vddval); + float_check(floatout,dacval); selected = (colselect * 24) + (rowselect+1); rowval = newvoltages[selected-1]; @@ -331,12 +385,12 @@ } pc.printf(" \r\n \r\n "); for (int x = 0; x < 48; x++) { - pc.printf("%1.3f %1.3f \r\n", originalvoltages[x], newvoltages[x]); + pc.printf("%1.3f %1.3f %1.3f \r\n", originalvoltages[x], newvoltages[x], floatout[x]); } //////////////////////// - wait(0.3); //THIS NEEDS TO GO AWAY! + wait(0.1); //THIS NEEDS TO GO AWAY! } // END OF SCANBUTTON IF STATEMENT