:)

Dependencies:   MbedJSONValue DebounceIn TextLCD USBDevice mbed WebSocketClient cc3000_hostdriver_mbedsocket Adafruit_LEDBackpack_2

Committer:
ddrew73
Date:
Tue Dec 09 20:06:17 2014 +0000
Revision:
16:028a8548ab22
Parent:
15:236d90e38951
Child:
17:fcc378db08f4
New float check with DAC;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ddrew73 0:16d2619002d7 1 #include "mbed.h"
ddrew73 1:0183a7d38878 2 #include <string>
ddrew73 0:16d2619002d7 3 #include "Adafruit_LEDBackpack.h"
ddrew73 0:16d2619002d7 4 #include "Adafruit_GFX.h"
ddrew73 0:16d2619002d7 5 #include "TextLCD.h"
ddrew73 0:16d2619002d7 6 #include "DebounceIn.h"
jn80842 3:161fed8bd027 7 #include "cc3000.h"
jn80842 3:161fed8bd027 8 #include "Websocket.h"
ddrew73 0:16d2619002d7 9
ddrew73 8:725d938b301b 10 //Debug
ddrew73 8:725d938b301b 11 Serial pc(USBTX, USBRX); // tx, rx
ddrew73 8:725d938b301b 12
ddrew73 8:725d938b301b 13 //For oscilliscope
ddrew73 8:725d938b301b 14 Timer timer;
ddrew73 8:725d938b301b 15
ddrew73 0:16d2619002d7 16 //LED stuff
ddrew73 9:5fa90677ff3e 17 I2C i2c_left(PTC11,PTC10);
ddrew73 7:7fbe8dc5e4fa 18 Adafruit_24bargraph ledbar_left=Adafruit_24bargraph(&i2c_left);
ddrew73 4:5d27966f93e4 19
ddrew73 9:5fa90677ff3e 20 I2C i2c_right(D7,D6);
ddrew73 7:7fbe8dc5e4fa 21 Adafruit_24bargraph ledbar_right=Adafruit_24bargraph(&i2c_right);
ddrew73 4:5d27966f93e4 22
jn80842 14:2d47b97c2028 23 void set_led(int index, int color) { // index range from 0-47
jn80842 14:2d47b97c2028 24 if (index<24) {
jn80842 14:2d47b97c2028 25 ledbar_left.setBar(index,color);
jn80842 14:2d47b97c2028 26 } else {
jn80842 14:2d47b97c2028 27 ledbar_right.setBar(index-24,color);
jn80842 14:2d47b97c2028 28 }
jn80842 14:2d47b97c2028 29 }
jn80842 14:2d47b97c2028 30
ddrew73 9:5fa90677ff3e 31 DebounceIn upbutton(PTA16);
ddrew73 10:cfd60b63ed11 32 DebounceIn downbutton(PTC12);
ddrew73 10:cfd60b63ed11 33 DebounceIn leftbutton(PTC17);
ddrew73 10:cfd60b63ed11 34 DebounceIn rightbutton(PTC16);
ddrew73 0:16d2619002d7 35
ddrew73 0:16d2619002d7 36 //Scanner stuff
ddrew73 0:16d2619002d7 37
ddrew73 10:cfd60b63ed11 38 DebounceIn scanbutton(PTC13);
ddrew73 0:16d2619002d7 39
ddrew73 9:5fa90677ff3e 40 DigitalOut A_in(PTB10);
ddrew73 9:5fa90677ff3e 41 DigitalOut B_in(PTB11);
ddrew73 9:5fa90677ff3e 42 DigitalOut C_in(PTE2);
ddrew73 9:5fa90677ff3e 43 DigitalOut D_in(PTE3);
ddrew73 9:5fa90677ff3e 44 DigitalOut E_in(PTE4);
ddrew73 9:5fa90677ff3e 45 DigitalOut F_in(PTE5);
ddrew73 0:16d2619002d7 46
ddrew73 16:028a8548ab22 47 DigitalOut scan_select(PTC3);
ddrew73 16:028a8548ab22 48
ddrew73 0:16d2619002d7 49 AnalogIn adc(PTB0);
ddrew73 16:028a8548ab22 50 AnalogOut dac(PTE30);
ddrew73 8:725d938b301b 51
ddrew73 0:16d2619002d7 52
ddrew73 0:16d2619002d7 53
ddrew73 0:16d2619002d7 54 //LCD stuff
jn80842 14:2d47b97c2028 55 //TextLCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2);
ddrew73 9:5fa90677ff3e 56 TextLCD lcd(PTC6,PTC5,D5,D4,D3,D2,TextLCD::LCD20x4);
ddrew73 0:16d2619002d7 57
jn80842 14:2d47b97c2028 58 void lcd_write_selected_info(int selected) {
jn80842 14:2d47b97c2028 59 lcd.cls();
jn80842 14:2d47b97c2028 60 lcd.locate(0,0);
jn80842 14:2d47b97c2028 61 lcd.printf("The ToastBoard");
jn80842 14:2d47b97c2028 62 lcd.locate(0,1);
jn80842 14:2d47b97c2028 63 lcd.printf("Selected row: %d",selected);
jn80842 14:2d47b97c2028 64 }
jn80842 14:2d47b97c2028 65
jn80842 14:2d47b97c2028 66 void lcd_write_voltage_info(float vddval,int selected,float rowval) {
jn80842 14:2d47b97c2028 67 lcd.cls();
jn80842 14:2d47b97c2028 68 lcd.locate(0,1);
jn80842 14:2d47b97c2028 69 lcd.printf("Vdd: %1.1f V",vddval);
jn80842 14:2d47b97c2028 70 lcd.locate(0,0);
ddrew73 15:236d90e38951 71 lcd.printf("Row %d: %1.1f V",selected,rowval);
jn80842 14:2d47b97c2028 72 }
jn80842 14:2d47b97c2028 73
ddrew73 10:cfd60b63ed11 74
ddrew73 10:cfd60b63ed11 75 //WIFI STUFF
jn80842 13:209da1dcb6e1 76
ddrew73 0:16d2619002d7 77
jn80842 3:161fed8bd027 78 // cc3000 KL25Z wifi connection
jn80842 3:161fed8bd027 79 // we need to define connection pins for:
jn80842 3:161fed8bd027 80 // - IRQ => (pin D3)
jn80842 3:161fed8bd027 81 // - Enable => (pin D5)
jn80842 3:161fed8bd027 82 // - SPI CS => (pin D10)
jn80842 3:161fed8bd027 83 // - SPI MOSI => (pin D11)
jn80842 3:161fed8bd027 84 // - SPI MISO => (pin D12)
jn80842 3:161fed8bd027 85 // - SPI CLK => (pin D13)
jn80842 3:161fed8bd027 86 // plus wifi network SSID, password, security level and smart-configuration flag.
jn80842 3:161fed8bd027 87
ddrew73 15:236d90e38951 88 /*
ddrew73 15:236d90e38951 89
ddrew73 9:5fa90677ff3e 90 mbed_cc3000::cc3000 wifi(D8, D9, D10, SPI(D11, D12, D13),
jn80842 14:2d47b97c2028 91 "SSID", "PASSWORD", WPA2, false);
jn80842 3:161fed8bd027 92 Websocket ws("ws://sockets.mbed.org/ws/toastboard/rw");
jn80842 3:161fed8bd027 93
ddrew73 15:236d90e38951 94
jn80842 12:c4b046975527 95 void add_to_json(const std::string& s, std::back_insert_iterator<std::string> oi) {
jn80842 14:2d47b97c2028 96 // this chunk of code lifted from the MbedJSONValue
jn80842 14:2d47b97c2028 97 char buf[7];
jn80842 12:c4b046975527 98 for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {
jn80842 14:2d47b97c2028 99 if ((unsigned char)*i < 0x20 || *i == 0x7f) {
jn80842 14:2d47b97c2028 100 sprintf(buf, "\\u%04x", *i & 0xff);
jn80842 14:2d47b97c2028 101 copy(buf, buf + 6, oi);
jn80842 14:2d47b97c2028 102 } else {
jn80842 14:2d47b97c2028 103 *oi++ = *i;
jn80842 14:2d47b97c2028 104 }
jn80842 14:2d47b97c2028 105 }
jn80842 14:2d47b97c2028 106 }
jn80842 14:2d47b97c2028 107
jn80842 14:2d47b97c2028 108 std::string build_json(float vddval,int selected,float clientdata[48]) {
jn80842 14:2d47b97c2028 109 std::string s;
jn80842 14:2d47b97c2028 110 std::back_insert_iterator<std::string> json_str = std::back_inserter(s);
jn80842 14:2d47b97c2028 111 char row[1] = ""; // holder for row tokens
jn80842 14:2d47b97c2028 112 char rowvoltage[4] = ""; // holder for voltage values
jn80842 14:2d47b97c2028 113 add_to_json("{\"vddval\":",json_str);
jn80842 14:2d47b97c2028 114 sprintf(rowvoltage,"%.1f",vddval);
jn80842 14:2d47b97c2028 115 add_to_json(rowvoltage,json_str);
jn80842 14:2d47b97c2028 116 add_to_json(", \"selected\":",json_str);
jn80842 14:2d47b97c2028 117 sprintf(rowvoltage,"%d",selected);
jn80842 14:2d47b97c2028 118 add_to_json(", \"rows\": [",json_str);
jn80842 14:2d47b97c2028 119 int append_comma = 0;
jn80842 14:2d47b97c2028 120 for (int i= 0; i < 48; i++) {
jn80842 14:2d47b97c2028 121 if (clientdata[i] != 100.0) { // don't pass on floating row vals
jn80842 14:2d47b97c2028 122 if (append_comma == 1) {
jn80842 14:2d47b97c2028 123 add_to_json(",",json_str);
jn80842 14:2d47b97c2028 124 } else {
jn80842 14:2d47b97c2028 125 append_comma = 1;
jn80842 14:2d47b97c2028 126 }
jn80842 14:2d47b97c2028 127 add_to_json("{\"",json_str);
jn80842 14:2d47b97c2028 128 sprintf(row, "%d", i);
jn80842 14:2d47b97c2028 129 add_to_json(row,json_str);
jn80842 14:2d47b97c2028 130 add_to_json("\":",json_str);
jn80842 14:2d47b97c2028 131 sprintf(rowvoltage,"%.1f",clientdata[i]);
jn80842 14:2d47b97c2028 132 add_to_json(rowvoltage,json_str);
jn80842 14:2d47b97c2028 133 add_to_json("}",json_str);
jn80842 14:2d47b97c2028 134 }
jn80842 14:2d47b97c2028 135 }
jn80842 14:2d47b97c2028 136 add_to_json("]}",json_str);
jn80842 14:2d47b97c2028 137 return s;
jn80842 14:2d47b97c2028 138 }
ddrew73 15:236d90e38951 139 */
jn80842 14:2d47b97c2028 140
jn80842 14:2d47b97c2028 141 bool voltages_equal(float voltage1,float voltage2) {
jn80842 14:2d47b97c2028 142 return (voltage1 > voltage2-0.01) && (voltage1 < voltage2+0.01);
jn80842 14:2d47b97c2028 143 }
jn80842 14:2d47b97c2028 144
jn80842 14:2d47b97c2028 145 void read_voltages(float voltages[48]) {
ddrew73 16:028a8548ab22 146 scan_select = 0;
jn80842 14:2d47b97c2028 147 int sn = 0;
ddrew73 15:236d90e38951 148 for (int i=0;i<48;i++) { // iterate over two columns of breadboard
ddrew73 15:236d90e38951 149 // iterate over 24 rows of each column
ddrew73 16:028a8548ab22 150 sn = i;
ddrew73 15:236d90e38951 151 D_in = (sn)%2;
ddrew73 15:236d90e38951 152 E_in = ((sn)/2)%2;
ddrew73 15:236d90e38951 153 F_in = ((sn)/4)%2;
ddrew73 15:236d90e38951 154 A_in = ((sn)/8)%2;
ddrew73 15:236d90e38951 155 B_in = ((sn)/16)%2;
ddrew73 15:236d90e38951 156 C_in = ((sn)/32)%2;
jn80842 14:2d47b97c2028 157
ddrew73 15:236d90e38951 158 voltages[sn] = adc.read();
ddrew73 15:236d90e38951 159
jn80842 14:2d47b97c2028 160 }
jn80842 14:2d47b97c2028 161 }
jn80842 14:2d47b97c2028 162
ddrew73 16:028a8548ab22 163 void float_check(float voltages[48],float dacval) {
ddrew73 16:028a8548ab22 164 int sn = 0;
ddrew73 16:028a8548ab22 165 for (int i=0;i<48;i++) { // iterate over two columns of breadboard
ddrew73 16:028a8548ab22 166 // iterate over 24 rows of each column
ddrew73 16:028a8548ab22 167 sn = i;
ddrew73 16:028a8548ab22 168 D_in = (sn)%2;
ddrew73 16:028a8548ab22 169 E_in = ((sn)/2)%2;
ddrew73 16:028a8548ab22 170 F_in = ((sn)/4)%2;
ddrew73 16:028a8548ab22 171 A_in = ((sn)/8)%2;
ddrew73 16:028a8548ab22 172 B_in = ((sn)/16)%2;
ddrew73 16:028a8548ab22 173 C_in = ((sn)/32)%2;
ddrew73 16:028a8548ab22 174
ddrew73 16:028a8548ab22 175 scan_select = 1;
ddrew73 16:028a8548ab22 176 scan_select = 0;
ddrew73 16:028a8548ab22 177 wait(0.01);
ddrew73 16:028a8548ab22 178 float in_val = adc.read();
ddrew73 16:028a8548ab22 179 voltages[sn] = in_val;
ddrew73 16:028a8548ab22 180
ddrew73 16:028a8548ab22 181 wait(0.01);
ddrew73 16:028a8548ab22 182
ddrew73 16:028a8548ab22 183 scan_select = 1;
ddrew73 16:028a8548ab22 184 scan_select = 0;
ddrew73 16:028a8548ab22 185 wait(0.01);
ddrew73 16:028a8548ab22 186 in_val = adc.read();
ddrew73 16:028a8548ab22 187
ddrew73 16:028a8548ab22 188
ddrew73 16:028a8548ab22 189 if ((in_val < voltages[sn]-0.004) || (in_val > voltages[sn]+0.004)){
ddrew73 16:028a8548ab22 190 voltages[sn] = 100;
ddrew73 16:028a8548ab22 191
ddrew73 16:028a8548ab22 192 }
ddrew73 16:028a8548ab22 193
ddrew73 16:028a8548ab22 194
ddrew73 16:028a8548ab22 195 }
ddrew73 16:028a8548ab22 196 }
ddrew73 16:028a8548ab22 197
ddrew73 16:028a8548ab22 198
ddrew73 16:028a8548ab22 199
ddrew73 16:028a8548ab22 200 void compare_voltages(float voltages[48], float clientdata[48], int colselect, int rowselect, float vddval, float floatchecked[48]) {
jn80842 14:2d47b97c2028 201 // get selected row voltage
ddrew73 16:028a8548ab22 202 scan_select = 0;
ddrew73 15:236d90e38951 203 float rowval = voltages[(colselect*24)+ rowselect];
jn80842 14:2d47b97c2028 204 for (int i=0;i<48;i++) {
jn80842 14:2d47b97c2028 205 int client_index = (colselect*24)+rowselect;
ddrew73 15:236d90e38951 206 int sn = i;//(colselect+1)*(rowselect+1);
ddrew73 15:236d90e38951 207 D_in = (sn)%2;
ddrew73 15:236d90e38951 208 E_in = ((sn)/2)%2;
ddrew73 15:236d90e38951 209 F_in = ((sn)/4)%2;
ddrew73 15:236d90e38951 210 A_in = ((sn)/8)%2;
ddrew73 15:236d90e38951 211 B_in = ((sn)/16)%2;
ddrew73 15:236d90e38951 212 C_in = ((sn)/32)%2;
jn80842 14:2d47b97c2028 213
jn80842 14:2d47b97c2028 214 float in_val = adc.read();
ddrew73 15:236d90e38951 215
ddrew73 16:028a8548ab22 216 if (floatchecked[sn] == 100){
ddrew73 16:028a8548ab22 217 set_led(i,LED_OFF);
ddrew73 16:028a8548ab22 218 clientdata[client_index] = 100.0;
ddrew73 16:028a8548ab22 219 }
ddrew73 16:028a8548ab22 220 else {
ddrew73 15:236d90e38951 221
jn80842 14:2d47b97c2028 222 if (!voltages_equal(voltages[i],in_val)) {
jn80842 14:2d47b97c2028 223 // this row is floating
ddrew73 15:236d90e38951 224 set_led(i,LED_OFF);
jn80842 14:2d47b97c2028 225 clientdata[client_index] = 100.0;
jn80842 14:2d47b97c2028 226 } else if (voltages_equal(voltages[i],vddval)) {
jn80842 14:2d47b97c2028 227 // this row matches vdd
jn80842 14:2d47b97c2028 228 set_led(i,LED_RED);
jn80842 14:2d47b97c2028 229 clientdata[client_index] = vddval;
jn80842 14:2d47b97c2028 230 } else if (voltages_equal(voltages[i],0.0)) {
jn80842 14:2d47b97c2028 231 // this row matches ground
jn80842 14:2d47b97c2028 232 set_led(i,LED_YELLOW);
jn80842 14:2d47b97c2028 233 clientdata[client_index] = 0.0;
jn80842 14:2d47b97c2028 234 } else if (voltages_equal(voltages[i],rowval)) {
jn80842 14:2d47b97c2028 235 // this row matches selected row
jn80842 14:2d47b97c2028 236 set_led(i,LED_GREEN);
jn80842 14:2d47b97c2028 237 clientdata[client_index] = rowval;
jn80842 14:2d47b97c2028 238 } else {
ddrew73 15:236d90e38951 239 set_led(i,LED_OFF);
jn80842 14:2d47b97c2028 240 clientdata[client_index] = voltages[i];
jn80842 12:c4b046975527 241 }
ddrew73 16:028a8548ab22 242 } // else if closing
ddrew73 16:028a8548ab22 243 } //for loop closing
ddrew73 16:028a8548ab22 244 } //compare_voltages function closing
jn80842 12:c4b046975527 245
ddrew73 7:7fbe8dc5e4fa 246
ddrew73 0:16d2619002d7 247 int main()
ddrew73 0:16d2619002d7 248 {
ddrew73 0:16d2619002d7 249
ddrew73 0:16d2619002d7 250 //Scan init
jn80842 14:2d47b97c2028 251 float originalvoltages[48] = {};
ddrew73 15:236d90e38951 252 float newvoltages[48] = {};
ddrew73 7:7fbe8dc5e4fa 253 float clientdata[48] = {};
jn80842 14:2d47b97c2028 254 float vddval = 0.0;
ddrew73 15:236d90e38951 255 float rowval = 0.0;
ddrew73 16:028a8548ab22 256 float dacval = 0.1;
ddrew73 16:028a8548ab22 257
ddrew73 16:028a8548ab22 258 float floatout[48] = {};
ddrew73 16:028a8548ab22 259 float floatoutsecond[48] = {};
ddrew73 0:16d2619002d7 260
ddrew73 0:16d2619002d7 261 //LED init
ddrew73 15:236d90e38951 262 int rowselect = 0, moved = 1, colselect = 0, selected = 0, oldselected = 49;
ddrew73 4:5d27966f93e4 263 ledbar_left.begin(0x70);
ddrew73 4:5d27966f93e4 264 ledbar_left.clear();
ddrew73 4:5d27966f93e4 265 ledbar_left.writeDisplay();
ddrew73 5:03d75ad40d5e 266
ddrew73 4:5d27966f93e4 267 ledbar_right.begin(0x70);
ddrew73 4:5d27966f93e4 268 ledbar_right.clear();
ddrew73 4:5d27966f93e4 269 ledbar_right.writeDisplay();
ddrew73 0:16d2619002d7 270
ddrew73 0:16d2619002d7 271 //LCD init
ddrew73 0:16d2619002d7 272 lcd.cls();
jn80842 14:2d47b97c2028 273 int written = 0;
jn80842 14:2d47b97c2028 274
ddrew73 15:236d90e38951 275 //wifi.init();
ddrew73 11:b520586dc0a1 276
ddrew73 9:5fa90677ff3e 277 //Osci
ddrew73 9:5fa90677ff3e 278 int loopcount = 0, pressed = 0;
ddrew73 9:5fa90677ff3e 279 float begintime = 0, endtime = 0, elapsed = 0;
ddrew73 0:16d2619002d7 280
ddrew73 0:16d2619002d7 281
ddrew73 0:16d2619002d7 282 while(1) {
ddrew73 15:236d90e38951 283 /*
jn80842 14:2d47b97c2028 284 if (wifi.is_connected() == false) {
jn80842 14:2d47b97c2028 285 pc.printf("trying to connect to wifi\r\n");
jn80842 14:2d47b97c2028 286 if (wifi.connect() == -1) {
jn80842 14:2d47b97c2028 287 pc.printf("Failed to connect\r\n");
jn80842 14:2d47b97c2028 288 } else {
jn80842 14:2d47b97c2028 289 pc.printf("IP address: %s \r\n", wifi.getIPAddress());
jn80842 14:2d47b97c2028 290 }
jn80842 14:2d47b97c2028 291 } else {
jn80842 14:2d47b97c2028 292 Websocket ws("ws://sockets.mbed.org/ws/toastboard/rw");
jn80842 14:2d47b97c2028 293 ws.connect();
jn80842 14:2d47b97c2028 294 }
ddrew73 5:03d75ad40d5e 295
ddrew73 15:236d90e38951 296 */
ddrew73 15:236d90e38951 297
ddrew73 15:236d90e38951 298
ddrew73 0:16d2619002d7 299 //Display
jn80842 14:2d47b97c2028 300 if (moved ==1) {
ddrew73 5:03d75ad40d5e 301 ledbar_left.clear();
ddrew73 5:03d75ad40d5e 302 ledbar_right.clear();
jn80842 14:2d47b97c2028 303 set_led((colselect*24+rowselect),LED_GREEN);
ddrew73 5:03d75ad40d5e 304 ledbar_left.writeDisplay();
ddrew73 5:03d75ad40d5e 305 ledbar_right.writeDisplay();
ddrew73 7:7fbe8dc5e4fa 306 }
ddrew73 0:16d2619002d7 307 //Moving the selected row
ddrew73 0:16d2619002d7 308 if (upbutton.read() == 0) {
ddrew73 0:16d2619002d7 309 rowselect = rowselect-1;
ddrew73 0:16d2619002d7 310 moved = 1;
jn80842 14:2d47b97c2028 311 written = 0;
ddrew73 15:236d90e38951 312 wait(0.3);
ddrew73 0:16d2619002d7 313 }
ddrew73 0:16d2619002d7 314
ddrew73 0:16d2619002d7 315 if (downbutton.read() == 0) {
ddrew73 0:16d2619002d7 316 rowselect = rowselect+1;
ddrew73 0:16d2619002d7 317 moved = 1;
jn80842 14:2d47b97c2028 318 written = 0;
ddrew73 15:236d90e38951 319 wait(0.3);
ddrew73 0:16d2619002d7 320 }
ddrew73 5:03d75ad40d5e 321
ddrew73 4:5d27966f93e4 322 if (leftbutton.read() == 0) {
ddrew73 4:5d27966f93e4 323 colselect = 0;
ddrew73 5:03d75ad40d5e 324 ledbar_right.clear();
ddrew73 5:03d75ad40d5e 325 moved =1;
jn80842 14:2d47b97c2028 326 written = 0;
ddrew73 15:236d90e38951 327 wait(0.3);
ddrew73 4:5d27966f93e4 328 }
ddrew73 5:03d75ad40d5e 329
ddrew73 4:5d27966f93e4 330 if (rightbutton.read() == 0) {
ddrew73 4:5d27966f93e4 331 colselect = 1;
ddrew73 5:03d75ad40d5e 332 ledbar_left.clear();
ddrew73 5:03d75ad40d5e 333 moved =1;
jn80842 14:2d47b97c2028 334 written = 0;
ddrew73 15:236d90e38951 335 wait(0.3);
ddrew73 5:03d75ad40d5e 336 }
ddrew73 0:16d2619002d7 337
ddrew73 0:16d2619002d7 338 //Boundary checking
ddrew73 0:16d2619002d7 339 if (rowselect > 23) {
ddrew73 0:16d2619002d7 340 rowselect = 23;
ddrew73 0:16d2619002d7 341 }
ddrew73 0:16d2619002d7 342 if (rowselect < 0) {
ddrew73 0:16d2619002d7 343 rowselect = 0;
ddrew73 0:16d2619002d7 344 }
ddrew73 0:16d2619002d7 345
ddrew73 15:236d90e38951 346 selected = (colselect * 24) + (rowselect+1);
ddrew73 15:236d90e38951 347
ddrew73 0:16d2619002d7 348 //Implementing scanning
ddrew73 0:16d2619002d7 349
ddrew73 0:16d2619002d7 350 if (scanbutton.read() == 0) {
ddrew73 15:236d90e38951 351 A_in = 0;
ddrew73 7:7fbe8dc5e4fa 352 B_in = 1;
ddrew73 7:7fbe8dc5e4fa 353 C_in = 1;
ddrew73 7:7fbe8dc5e4fa 354 D_in = 1;
ddrew73 15:236d90e38951 355 E_in = 0;
ddrew73 15:236d90e38951 356 F_in = 0;
ddrew73 11:b520586dc0a1 357
ddrew73 7:7fbe8dc5e4fa 358 vddval = adc.read();
ddrew73 0:16d2619002d7 359
ddrew73 7:7fbe8dc5e4fa 360 ledbar_left.clear();
ddrew73 7:7fbe8dc5e4fa 361 ledbar_right.clear();
ddrew73 1:0183a7d38878 362
jn80842 14:2d47b97c2028 363 // first set of voltages read into old_volt_mat
jn80842 14:2d47b97c2028 364 read_voltages(originalvoltages);
ddrew73 16:028a8548ab22 365 wait(0.4);
ddrew73 15:236d90e38951 366 read_voltages(newvoltages);
jn80842 14:2d47b97c2028 367 // second set for comparison, read into clientdata
ddrew73 16:028a8548ab22 368 wait(0.4);
ddrew73 16:028a8548ab22 369 compare_voltages(originalvoltages,clientdata,colselect,rowselect,vddval,floatout);
ddrew73 16:028a8548ab22 370
ddrew73 15:236d90e38951 371 wait(0.2);
ddrew73 16:028a8548ab22 372 float_check(floatout,dacval);
ddrew73 0:16d2619002d7 373
ddrew73 15:236d90e38951 374 selected = (colselect * 24) + (rowselect+1);
ddrew73 15:236d90e38951 375 rowval = newvoltages[selected-1];
ddrew73 11:b520586dc0a1 376
jn80842 14:2d47b97c2028 377 written = 0;
jn80842 14:2d47b97c2028 378 moved = 0;
ddrew73 11:b520586dc0a1 379
ddrew73 8:725d938b301b 380 //DEBUGGING TOOLS //////////////
ddrew73 11:b520586dc0a1 381
ddrew73 15:236d90e38951 382 pc.printf("\r\n%1.3f %1.3f \r\n", vddval, rowval);
jn80842 14:2d47b97c2028 383 for (int i = 0; i<48; i++) {
jn80842 14:2d47b97c2028 384 pc.printf(" %1.3f ", clientdata[i]);
jn80842 14:2d47b97c2028 385 }
jn80842 14:2d47b97c2028 386 pc.printf(" \r\n \r\n ");
jn80842 14:2d47b97c2028 387 for (int x = 0; x < 48; x++) {
ddrew73 16:028a8548ab22 388 pc.printf("%1.3f %1.3f %1.3f \r\n", originalvoltages[x], newvoltages[x], floatout[x]);
jn80842 14:2d47b97c2028 389 }
jn80842 14:2d47b97c2028 390 ////////////////////////
ddrew73 11:b520586dc0a1 391
ddrew73 11:b520586dc0a1 392
ddrew73 16:028a8548ab22 393 wait(0.1); //THIS NEEDS TO GO AWAY!
ddrew73 11:b520586dc0a1 394
ddrew73 11:b520586dc0a1 395 } // END OF SCANBUTTON IF STATEMENT
ddrew73 11:b520586dc0a1 396
jn80842 14:2d47b97c2028 397 if (moved==0 && written == 0) {
ddrew73 7:7fbe8dc5e4fa 398 ledbar_left.writeDisplay();
ddrew73 7:7fbe8dc5e4fa 399 ledbar_right.writeDisplay();
ddrew73 15:236d90e38951 400 lcd_write_voltage_info(vddval*3.3,selected,rowval*3.3);
ddrew73 15:236d90e38951 401
ddrew73 15:236d90e38951 402 /*
jn80842 13:209da1dcb6e1 403 // send data to websocket
jn80842 14:2d47b97c2028 404 if (wifi.is_connected()) {
jn80842 14:2d47b97c2028 405 std::string json = build_json(vddval,selected,clientdata);
jn80842 14:2d47b97c2028 406 char * writable = new char[json.size() + 1];
jn80842 14:2d47b97c2028 407 std::copy(json.begin(), json.end(), writable);
jn80842 14:2d47b97c2028 408 writable[json.size()] = '\0';
jn80842 14:2d47b97c2028 409 ws.send(writable);
jn80842 14:2d47b97c2028 410 delete[] writable;
jn80842 14:2d47b97c2028 411 delete[] &json;
jn80842 14:2d47b97c2028 412 }
ddrew73 15:236d90e38951 413 */
ddrew73 15:236d90e38951 414
jn80842 14:2d47b97c2028 415 written = 1;
ddrew73 15:236d90e38951 416 } else if (oldselected != selected) {
jn80842 14:2d47b97c2028 417 lcd_write_selected_info(selected);
ddrew73 15:236d90e38951 418
ddrew73 11:b520586dc0a1 419 }
ddrew73 15:236d90e38951 420 oldselected = selected;
ddrew73 5:03d75ad40d5e 421
ddrew73 5:03d75ad40d5e 422
ddrew73 5:03d75ad40d5e 423
ddrew73 5:03d75ad40d5e 424
ddrew73 4:5d27966f93e4 425
ddrew73 11:b520586dc0a1 426
ddrew73 7:7fbe8dc5e4fa 427
ddrew73 7:7fbe8dc5e4fa 428
ddrew73 0:16d2619002d7 429
ddrew73 0:16d2619002d7 430
ddrew73 4:5d27966f93e4 431
ddrew73 4:5d27966f93e4 432
ddrew73 4:5d27966f93e4 433
ddrew73 7:7fbe8dc5e4fa 434 } // END OF WHILE(1)
ddrew73 7:7fbe8dc5e4fa 435
ddrew73 7:7fbe8dc5e4fa 436
ddrew73 7:7fbe8dc5e4fa 437
ddrew73 4:5d27966f93e4 438
ddrew73 7:7fbe8dc5e4fa 439 } // END OF INT MAIN
ddrew73 7:7fbe8dc5e4fa 440
ddrew73 7:7fbe8dc5e4fa 441
ddrew73 11:b520586dc0a1 442 /*
ddrew73 11:b520586dc0a1 443 OSCILLISCOPE
ddrew73 7:7fbe8dc5e4fa 444
ddrew73 7:7fbe8dc5e4fa 445
ddrew73 11:b520586dc0a1 446 while (scanbutton == 0){
ddrew73 11:b520586dc0a1 447 if (loopcount = 0){
ddrew73 11:b520586dc0a1 448 timer.reset();
ddrew73 11:b520586dc0a1 449 timer.start();
ddrew73 11:b520586dc0a1 450 begintime = timer.read_ms();
ddrew73 11:b520586dc0a1 451 pressed == 1;
ddrew73 11:b520586dc0a1 452 }
ddrew73 7:7fbe8dc5e4fa 453
ddrew73 11:b520586dc0a1 454 int sn = (colselect + 1)*(rowselect + 1);
ddrew73 11:b520586dc0a1 455 A_in = (sn-1)&2;
ddrew73 11:b520586dc0a1 456 B_in = ((sn-1)/2)%2;
ddrew73 11:b520586dc0a1 457 C_in = ((sn-1)/4)%2;
ddrew73 11:b520586dc0a1 458 D_in = ((sn-1)/8)%2;
ddrew73 11:b520586dc0a1 459 E_in = ((sn-1)/16)%2;
ddrew73 11:b520586dc0a1 460 F_in = ((sn-1)/32)%2;
ddrew73 11:b520586dc0a1 461 volt_buffer[loopcount] = adc.read();
ddrew73 8:725d938b301b 462
ddrew73 8:725d938b301b 463
ddrew73 11:b520586dc0a1 464 loopcount = loopcount +1;
ddrew73 11:b520586dc0a1 465 } // BREAK THE WHILE SCANBUTTON
ddrew73 8:725d938b301b 466
ddrew73 11:b520586dc0a1 467 if (pressed == 1){
ddrew73 11:b520586dc0a1 468 timer.stop();
ddrew73 11:b520586dc0a1 469 endtime = timer.read_ms();
ddrew73 11:b520586dc0a1 470 elapsed = endtime - begintime;
ddrew73 8:725d938b301b 471
ddrew73 11:b520586dc0a1 472 DO ENTIRE SCAN STUFF
ddrew73 8:725d938b301b 473
ddrew73 11:b520586dc0a1 474 pressed = 0;
ddrew73 11:b520586dc0a1 475 }
ddrew73 8:725d938b301b 476
ddrew73 11:b520586dc0a1 477 */