:)

Dependencies:   MbedJSONValue DebounceIn TextLCD USBDevice mbed WebSocketClient cc3000_hostdriver_mbedsocket Adafruit_LEDBackpack_2

Committer:
jn80842
Date:
Thu Dec 11 19:15:20 2014 +0000
Revision:
21:4ec999be140a
Parent:
13:209da1dcb6e1
dan/filip's changes to handle floating rows

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jn80842 13:209da1dcb6e1 1 #include "mbed.h"
jn80842 13:209da1dcb6e1 2 #include <string>
jn80842 13:209da1dcb6e1 3 #include "Adafruit_LEDBackpack.h"
jn80842 13:209da1dcb6e1 4 #include "Adafruit_GFX.h"
jn80842 13:209da1dcb6e1 5 #include "TextLCD.h"
jn80842 13:209da1dcb6e1 6 #include "DebounceIn.h"
jn80842 13:209da1dcb6e1 7 #include "cc3000.h"
jn80842 13:209da1dcb6e1 8 #include "Websocket.h"
jn80842 13:209da1dcb6e1 9 #include "MbedJSONValue.h"
jn80842 13:209da1dcb6e1 10
jn80842 13:209da1dcb6e1 11 //Debug
jn80842 13:209da1dcb6e1 12 Serial pc(USBTX, USBRX); // tx, rx
jn80842 13:209da1dcb6e1 13
jn80842 13:209da1dcb6e1 14 //For oscilliscope
jn80842 13:209da1dcb6e1 15 Timer timer;
jn80842 13:209da1dcb6e1 16
jn80842 13:209da1dcb6e1 17 //LED stuff
jn80842 13:209da1dcb6e1 18 I2C i2c_left(PTC11,PTC10);
jn80842 13:209da1dcb6e1 19 Adafruit_24bargraph ledbar_left=Adafruit_24bargraph(&i2c_left);
jn80842 13:209da1dcb6e1 20
jn80842 13:209da1dcb6e1 21 I2C i2c_right(D7,D6);
jn80842 13:209da1dcb6e1 22 Adafruit_24bargraph ledbar_right=Adafruit_24bargraph(&i2c_right);
jn80842 13:209da1dcb6e1 23
jn80842 13:209da1dcb6e1 24 DebounceIn upbutton(PTA16);
jn80842 13:209da1dcb6e1 25 DebounceIn downbutton(PTC12);
jn80842 13:209da1dcb6e1 26 DebounceIn leftbutton(PTC17);
jn80842 13:209da1dcb6e1 27 DebounceIn rightbutton(PTC16);
jn80842 13:209da1dcb6e1 28
jn80842 13:209da1dcb6e1 29 //Scanner stuff
jn80842 13:209da1dcb6e1 30
jn80842 13:209da1dcb6e1 31 DebounceIn scanbutton(PTC13);
jn80842 13:209da1dcb6e1 32
jn80842 13:209da1dcb6e1 33 DigitalOut A_in(PTB10);
jn80842 13:209da1dcb6e1 34 DigitalOut B_in(PTB11);
jn80842 13:209da1dcb6e1 35 DigitalOut C_in(PTE2);
jn80842 13:209da1dcb6e1 36 DigitalOut D_in(PTE3);
jn80842 13:209da1dcb6e1 37 DigitalOut E_in(PTE4);
jn80842 13:209da1dcb6e1 38 DigitalOut F_in(PTE5);
jn80842 13:209da1dcb6e1 39
jn80842 13:209da1dcb6e1 40 AnalogIn adc(PTB0);
jn80842 13:209da1dcb6e1 41
jn80842 13:209da1dcb6e1 42
jn80842 13:209da1dcb6e1 43
jn80842 13:209da1dcb6e1 44
jn80842 13:209da1dcb6e1 45 //LCD stuff
jn80842 13:209da1dcb6e1 46 //extLCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2);
jn80842 13:209da1dcb6e1 47 TextLCD lcd(PTC6,PTC5,D5,D4,D3,D2,TextLCD::LCD20x4);
jn80842 13:209da1dcb6e1 48
jn80842 13:209da1dcb6e1 49
jn80842 13:209da1dcb6e1 50 //WIFI STUFF
jn80842 13:209da1dcb6e1 51 /*
jn80842 13:209da1dcb6e1 52
jn80842 13:209da1dcb6e1 53 // cc3000 KL25Z wifi connection
jn80842 13:209da1dcb6e1 54 // we need to define connection pins for:
jn80842 13:209da1dcb6e1 55 // - IRQ => (pin D3)
jn80842 13:209da1dcb6e1 56 // - Enable => (pin D5)
jn80842 13:209da1dcb6e1 57 // - SPI CS => (pin D10)
jn80842 13:209da1dcb6e1 58 // - SPI MOSI => (pin D11)
jn80842 13:209da1dcb6e1 59 // - SPI MISO => (pin D12)
jn80842 13:209da1dcb6e1 60 // - SPI CLK => (pin D13)
jn80842 13:209da1dcb6e1 61 // plus wifi network SSID, password, security level and smart-configuration flag.
jn80842 13:209da1dcb6e1 62
jn80842 13:209da1dcb6e1 63 mbed_cc3000::cc3000 wifi(D8, D9, D10, SPI(D11, D12, D13),
jn80842 13:209da1dcb6e1 64 "SSID", "PASSWORD", WPA2, false);
jn80842 13:209da1dcb6e1 65 Websocket ws("ws://sockets.mbed.org/ws/toastboard/rw");
jn80842 13:209da1dcb6e1 66
jn80842 13:209da1dcb6e1 67 MbedJSONValue demo;
jn80842 13:209da1dcb6e1 68 */
jn80842 13:209da1dcb6e1 69
jn80842 13:209da1dcb6e1 70
jn80842 13:209da1dcb6e1 71
jn80842 13:209da1dcb6e1 72 int main()
jn80842 13:209da1dcb6e1 73 {
jn80842 13:209da1dcb6e1 74
jn80842 13:209da1dcb6e1 75 //Scan init
jn80842 13:209da1dcb6e1 76
jn80842 13:209da1dcb6e1 77 int con_mat[24][2] = {};
jn80842 13:209da1dcb6e1 78 float volt_mat[24][2] = {};
jn80842 13:209da1dcb6e1 79 float clientdata[48] = {};
jn80842 13:209da1dcb6e1 80 float rowval = 0, vddval = 0;
jn80842 13:209da1dcb6e1 81
jn80842 13:209da1dcb6e1 82 //LED init
jn80842 13:209da1dcb6e1 83 int rowselect = 0, moved = 1, colselect = 0, selected = 0;
jn80842 13:209da1dcb6e1 84 ledbar_left.begin(0x70);
jn80842 13:209da1dcb6e1 85 ledbar_left.clear();
jn80842 13:209da1dcb6e1 86 ledbar_left.writeDisplay();
jn80842 13:209da1dcb6e1 87
jn80842 13:209da1dcb6e1 88 ledbar_right.begin(0x70);
jn80842 13:209da1dcb6e1 89 ledbar_right.clear();
jn80842 13:209da1dcb6e1 90 ledbar_right.writeDisplay();
jn80842 13:209da1dcb6e1 91
jn80842 13:209da1dcb6e1 92 //LCD init
jn80842 13:209da1dcb6e1 93 lcd.cls();
jn80842 13:209da1dcb6e1 94
jn80842 13:209da1dcb6e1 95 //Osci
jn80842 13:209da1dcb6e1 96 int loopcount = 0, pressed = 0;
jn80842 13:209da1dcb6e1 97 float begintime = 0, endtime = 0, elapsed = 0;
jn80842 13:209da1dcb6e1 98
jn80842 13:209da1dcb6e1 99
jn80842 13:209da1dcb6e1 100 while(1) {
jn80842 13:209da1dcb6e1 101
jn80842 13:209da1dcb6e1 102 //Display
jn80842 13:209da1dcb6e1 103
jn80842 13:209da1dcb6e1 104 if (colselect == 0 && moved == 1) {
jn80842 13:209da1dcb6e1 105 ledbar_left.clear();
jn80842 13:209da1dcb6e1 106 ledbar_right.clear();
jn80842 13:209da1dcb6e1 107 ledbar_left.setBar(rowselect,LED_GREEN);
jn80842 13:209da1dcb6e1 108 ledbar_left.writeDisplay();
jn80842 13:209da1dcb6e1 109 ledbar_right.writeDisplay();
jn80842 13:209da1dcb6e1 110 } else if (colselect == 1 && moved == 1) {
jn80842 13:209da1dcb6e1 111 ledbar_left.clear();
jn80842 13:209da1dcb6e1 112 ledbar_right.clear();
jn80842 13:209da1dcb6e1 113 ledbar_right.setBar(rowselect,LED_GREEN);
jn80842 13:209da1dcb6e1 114 ledbar_right.writeDisplay();
jn80842 13:209da1dcb6e1 115 ledbar_left.writeDisplay();
jn80842 13:209da1dcb6e1 116 }
jn80842 13:209da1dcb6e1 117 //Moving the selected row
jn80842 13:209da1dcb6e1 118 if (upbutton.read() == 0) {
jn80842 13:209da1dcb6e1 119
jn80842 13:209da1dcb6e1 120 rowselect = rowselect-1;
jn80842 13:209da1dcb6e1 121 moved = 1;
jn80842 13:209da1dcb6e1 122 wait(0.75);
jn80842 13:209da1dcb6e1 123 }
jn80842 13:209da1dcb6e1 124
jn80842 13:209da1dcb6e1 125 if (downbutton.read() == 0) {
jn80842 13:209da1dcb6e1 126
jn80842 13:209da1dcb6e1 127 rowselect = rowselect+1;
jn80842 13:209da1dcb6e1 128 moved = 1;
jn80842 13:209da1dcb6e1 129 wait(0.75);
jn80842 13:209da1dcb6e1 130 }
jn80842 13:209da1dcb6e1 131
jn80842 13:209da1dcb6e1 132 if (leftbutton.read() == 0) {
jn80842 13:209da1dcb6e1 133 colselect = 0;
jn80842 13:209da1dcb6e1 134 ledbar_right.clear();
jn80842 13:209da1dcb6e1 135 moved =1;
jn80842 13:209da1dcb6e1 136 wait(0.75);
jn80842 13:209da1dcb6e1 137
jn80842 13:209da1dcb6e1 138 }
jn80842 13:209da1dcb6e1 139
jn80842 13:209da1dcb6e1 140 if (rightbutton.read() == 0) {
jn80842 13:209da1dcb6e1 141 colselect = 1;
jn80842 13:209da1dcb6e1 142 ledbar_left.clear();
jn80842 13:209da1dcb6e1 143 moved =1;
jn80842 13:209da1dcb6e1 144 wait(0.75);
jn80842 13:209da1dcb6e1 145
jn80842 13:209da1dcb6e1 146
jn80842 13:209da1dcb6e1 147 }
jn80842 13:209da1dcb6e1 148
jn80842 13:209da1dcb6e1 149 //Boundary checking
jn80842 13:209da1dcb6e1 150 if (rowselect > 23) {
jn80842 13:209da1dcb6e1 151 rowselect = 23;
jn80842 13:209da1dcb6e1 152 }
jn80842 13:209da1dcb6e1 153 if (rowselect < 0) {
jn80842 13:209da1dcb6e1 154 rowselect = 0;
jn80842 13:209da1dcb6e1 155 }
jn80842 13:209da1dcb6e1 156
jn80842 13:209da1dcb6e1 157 //Implementing scanning
jn80842 13:209da1dcb6e1 158
jn80842 13:209da1dcb6e1 159 if (scanbutton.read() == 0) {
jn80842 13:209da1dcb6e1 160 A_in = 1;
jn80842 13:209da1dcb6e1 161 B_in = 1;
jn80842 13:209da1dcb6e1 162 C_in = 1;
jn80842 13:209da1dcb6e1 163 D_in = 1;
jn80842 13:209da1dcb6e1 164 E_in = 1;
jn80842 13:209da1dcb6e1 165 F_in = 1;
jn80842 13:209da1dcb6e1 166
jn80842 13:209da1dcb6e1 167 vddval = adc.read();
jn80842 13:209da1dcb6e1 168
jn80842 13:209da1dcb6e1 169 //SET MULTIPLEXER TO READ SELECTED ROW
jn80842 13:209da1dcb6e1 170 // Sample the 'selected' node
jn80842 13:209da1dcb6e1 171
jn80842 13:209da1dcb6e1 172 int sn = (colselect + 1)*(rowselect + 1);
jn80842 13:209da1dcb6e1 173 A_in = (sn-1)&2;
jn80842 13:209da1dcb6e1 174 B_in = ((sn-1)/2)%2;
jn80842 13:209da1dcb6e1 175 C_in = ((sn-1)/4)%2;
jn80842 13:209da1dcb6e1 176 D_in = ((sn-1)/8)%2;
jn80842 13:209da1dcb6e1 177 E_in = ((sn-1)/16)%2;
jn80842 13:209da1dcb6e1 178 F_in = ((sn-1)/32)%2;
jn80842 13:209da1dcb6e1 179 rowval = adc.read();
jn80842 13:209da1dcb6e1 180
jn80842 13:209da1dcb6e1 181 ledbar_left.clear();
jn80842 13:209da1dcb6e1 182 ledbar_right.clear();
jn80842 13:209da1dcb6e1 183
jn80842 13:209da1dcb6e1 184 for (int u = 0; u < 2; u++) {
jn80842 13:209da1dcb6e1 185
jn80842 13:209da1dcb6e1 186 for (int x = 0; x < 2; x++) {
jn80842 13:209da1dcb6e1 187 for (int y = 0; y < 24; y++) {
jn80842 13:209da1dcb6e1 188
jn80842 13:209da1dcb6e1 189
jn80842 13:209da1dcb6e1 190 int sn = (colselect+1)*(rowselect+1);
jn80842 13:209da1dcb6e1 191 A_in = (sn-1)&2;
jn80842 13:209da1dcb6e1 192 B_in = ((sn-1)/2)%2;
jn80842 13:209da1dcb6e1 193 C_in = ((sn-1)/4)%2;
jn80842 13:209da1dcb6e1 194 D_in = ((sn-1)/8)%2;
jn80842 13:209da1dcb6e1 195 E_in = ((sn-1)/16)%2;
jn80842 13:209da1dcb6e1 196 F_in = ((sn-1)/32)%2;
jn80842 13:209da1dcb6e1 197
jn80842 13:209da1dcb6e1 198 float in_val = adc.read();
jn80842 13:209da1dcb6e1 199
jn80842 13:209da1dcb6e1 200
jn80842 13:209da1dcb6e1 201 if (u == 0) {
jn80842 13:209da1dcb6e1 202 old_volt_map[x][y] = in_val
jn80842 13:209da1dcb6e1 203 } else {
jn80842 13:209da1dcb6e1 204 volt_map[x][y] = in_val
jn80842 13:209da1dcb6e1 205 if (old_volt_map[x][y] != volt_map[x][y] ) {
jn80842 13:209da1dcb6e1 206 volt_map[x][y] = 100;
jn80842 13:209da1dcb6e1 207 }
jn80842 13:209da1dcb6e1 208 if (x == 1) {
jn80842 13:209da1dcb6e1 209 int z = y+24;
jn80842 13:209da1dcb6e1 210 clientdata[z] = in_val;
jn80842 13:209da1dcb6e1 211 } else {
jn80842 13:209da1dcb6e1 212 clientdata[y] = in_val;
jn80842 13:209da1dcb6e1 213 }
jn80842 13:209da1dcb6e1 214
jn80842 13:209da1dcb6e1 215
jn80842 13:209da1dcb6e1 216 if ((in_val > vddval-0.01) && (in_val < vddval+0.01)) {
jn80842 13:209da1dcb6e1 217 con_mat[x][y] = 2;
jn80842 13:209da1dcb6e1 218 if (x == 0) {
jn80842 13:209da1dcb6e1 219 ledbar_left.setBar(y,LED_RED);
jn80842 13:209da1dcb6e1 220 } else {
jn80842 13:209da1dcb6e1 221 ledbar_right.setBar(y,LED_RED);
jn80842 13:209da1dcb6e1 222 }
jn80842 13:209da1dcb6e1 223 } else if (in_val == 0) {
jn80842 13:209da1dcb6e1 224 con_mat[x][y] = 3;
jn80842 13:209da1dcb6e1 225 if (x == 0) {
jn80842 13:209da1dcb6e1 226 ledbar_left.setBar(y,LED_YELLOW);
jn80842 13:209da1dcb6e1 227 } else {
jn80842 13:209da1dcb6e1 228 ledbar_right.setBar(y,LED_YELLOW);
jn80842 13:209da1dcb6e1 229 }
jn80842 13:209da1dcb6e1 230 } else if ((in_val > rowval-0.01) && (in_val < rowval+0.01)) {
jn80842 13:209da1dcb6e1 231 con_mat[x][y] = 1;
jn80842 13:209da1dcb6e1 232 if (x == 0) {
jn80842 13:209da1dcb6e1 233 ledbar_left.setBar(y,LED_GREEN);
jn80842 13:209da1dcb6e1 234 } else {
jn80842 13:209da1dcb6e1 235 ledbar_right.setBar(y,LED_GREEN);
jn80842 13:209da1dcb6e1 236 }
jn80842 13:209da1dcb6e1 237 }
jn80842 13:209da1dcb6e1 238 else if (volt_mat[x][y]==100) {
jn80842 13:209da1dcb6e1 239 con_mat[x][y] = 4;
jn80842 13:209da1dcb6e1 240 if (x == 0) {
jn80842 13:209da1dcb6e1 241 ledbar_left.setBar(y,LED_OFF);
jn80842 13:209da1dcb6e1 242 } else {
jn80842 13:209da1dcb6e1 243 ledbar_right.setBar(y,LED_OFF);
jn80842 13:209da1dcb6e1 244 }
jn80842 13:209da1dcb6e1 245 }
jn80842 13:209da1dcb6e1 246 else {
jn80842 13:209da1dcb6e1 247 con_mat[x][y] = 0;
jn80842 13:209da1dcb6e1 248 }
jn80842 13:209da1dcb6e1 249
jn80842 13:209da1dcb6e1 250 }}} //END OF ROWSCAN FOR LOOP
jn80842 13:209da1dcb6e1 251
jn80842 13:209da1dcb6e1 252 selected = rowselect;
jn80842 13:209da1dcb6e1 253 if (colselect == 1) {
jn80842 13:209da1dcb6e1 254 selected = selected+24;
jn80842 13:209da1dcb6e1 255 }
jn80842 13:209da1dcb6e1 256
jn80842 13:209da1dcb6e1 257 /*
jn80842 13:209da1dcb6e1 258 //STUFF INTO JSON FORMAT
jn80842 13:209da1dcb6e1 259 char str[1];
jn80842 13:209da1dcb6e1 260 for (int i= 0; i < 48; i++) {
jn80842 13:209da1dcb6e1 261 sprintf(str, "%d", i);
jn80842 13:209da1dcb6e1 262 demo[str] = clientdata[i];
jn80842 13:209da1dcb6e1 263 }
jn80842 13:209da1dcb6e1 264 demo["vdd"] = vddval;
jn80842 13:209da1dcb6e1 265 demo["rowval"] = rowval;
jn80842 13:209da1dcb6e1 266
jn80842 13:209da1dcb6e1 267 demo["selected"] = selected;
jn80842 13:209da1dcb6e1 268 */
jn80842 13:209da1dcb6e1 269
jn80842 13:209da1dcb6e1 270
jn80842 13:209da1dcb6e1 271 moved = 0;
jn80842 13:209da1dcb6e1 272
jn80842 13:209da1dcb6e1 273
jn80842 13:209da1dcb6e1 274 //DEBUGGING TOOLS //////////////
jn80842 13:209da1dcb6e1 275
jn80842 13:209da1dcb6e1 276 pc.printf("\r\n%1.3f %1.3f \r\n", vddval, rowval);
jn80842 13:209da1dcb6e1 277 for (int i = 0; i<48; i++) {
jn80842 13:209da1dcb6e1 278 pc.printf(" %1.3f ", clientdata[i]);
jn80842 13:209da1dcb6e1 279 }
jn80842 13:209da1dcb6e1 280 pc.printf(" \r\n \r\n ");
jn80842 13:209da1dcb6e1 281 for (int x = 0; x < 2; x++) {
jn80842 13:209da1dcb6e1 282 for (int y = 0; y < 24; y++) {
jn80842 13:209da1dcb6e1 283 pc.printf("%1.3f \r\n", volt_mat[x][y]);
jn80842 13:209da1dcb6e1 284 }
jn80842 13:209da1dcb6e1 285 }
jn80842 13:209da1dcb6e1 286 ////////////////////////
jn80842 13:209da1dcb6e1 287
jn80842 13:209da1dcb6e1 288
jn80842 13:209da1dcb6e1 289 wait(1); //THIS NEEDS TO GO AWAY! :}
jn80842 13:209da1dcb6e1 290
jn80842 13:209da1dcb6e1 291 } // END OF SCANBUTTON IF STATEMENT
jn80842 13:209da1dcb6e1 292
jn80842 13:209da1dcb6e1 293 if (moved==0) {
jn80842 13:209da1dcb6e1 294 ledbar_left.writeDisplay();
jn80842 13:209da1dcb6e1 295 ledbar_right.writeDisplay();
jn80842 13:209da1dcb6e1 296 lcd.cls();
jn80842 13:209da1dcb6e1 297 lcd.locate(0,1);
jn80842 13:209da1dcb6e1 298 lcd.printf("Vdd: %1.1f V",vddval);
jn80842 13:209da1dcb6e1 299 lcd.locate(0,0);
jn80842 13:209da1dcb6e1 300 lcd.printf("Row %d: %1.1f V",selected,rowval);
jn80842 13:209da1dcb6e1 301 } else {
jn80842 13:209da1dcb6e1 302 lcd.cls();
jn80842 13:209da1dcb6e1 303 string programname = "The ToastBoard";
jn80842 13:209da1dcb6e1 304 string instructions = "Select a row";
jn80842 13:209da1dcb6e1 305 lcd.locate(0,0);
jn80842 13:209da1dcb6e1 306 lcd.printf("%s",programname.c_str());
jn80842 13:209da1dcb6e1 307 lcd.locate(0,1);
jn80842 13:209da1dcb6e1 308 lcd.printf("%s",instructions.c_str());
jn80842 13:209da1dcb6e1 309 }
jn80842 13:209da1dcb6e1 310
jn80842 13:209da1dcb6e1 311
jn80842 13:209da1dcb6e1 312
jn80842 13:209da1dcb6e1 313
jn80842 13:209da1dcb6e1 314
jn80842 13:209da1dcb6e1 315
jn80842 13:209da1dcb6e1 316
jn80842 13:209da1dcb6e1 317
jn80842 13:209da1dcb6e1 318
jn80842 13:209da1dcb6e1 319
jn80842 13:209da1dcb6e1 320
jn80842 13:209da1dcb6e1 321
jn80842 13:209da1dcb6e1 322
jn80842 13:209da1dcb6e1 323 } // END OF WHILE(1)
jn80842 13:209da1dcb6e1 324
jn80842 13:209da1dcb6e1 325
jn80842 13:209da1dcb6e1 326
jn80842 13:209da1dcb6e1 327
jn80842 13:209da1dcb6e1 328 } // END OF INT MAIN
jn80842 13:209da1dcb6e1 329
jn80842 13:209da1dcb6e1 330
jn80842 13:209da1dcb6e1 331 /*
jn80842 13:209da1dcb6e1 332 FLOAT NODE CHECKER
jn80842 13:209da1dcb6e1 333 add another "for" around the two for the 48 row checker:
jn80842 13:209da1dcb6e1 334
jn80842 13:209da1dcb6e1 335 if (u == 0){
jn80842 13:209da1dcb6e1 336 old_volt_map[x,y] = in_val
jn80842 13:209da1dcb6e1 337 }
jn80842 13:209da1dcb6e1 338 else{
jn80842 13:209da1dcb6e1 339 volt_map[x,y] = in_val
jn80842 13:209da1dcb6e1 340 if (old_volt_map[x,y] != volt_map[x,y] ) {
jn80842 13:209da1dcb6e1 341 volt_map[x,y] = 100;
jn80842 13:209da1dcb6e1 342 }
jn80842 13:209da1dcb6e1 343
jn80842 13:209da1dcb6e1 344 PUT ALL ROW LIGHTING (CON_MAT) STUFF HERE
jn80842 13:209da1dcb6e1 345 }
jn80842 13:209da1dcb6e1 346
jn80842 13:209da1dcb6e1 347 */
jn80842 13:209da1dcb6e1 348
jn80842 13:209da1dcb6e1 349 /*
jn80842 13:209da1dcb6e1 350 OSCILLISCOPE
jn80842 13:209da1dcb6e1 351
jn80842 13:209da1dcb6e1 352
jn80842 13:209da1dcb6e1 353 while (scanbutton == 0){
jn80842 13:209da1dcb6e1 354 if (loopcount = 0){
jn80842 13:209da1dcb6e1 355 timer.reset();
jn80842 13:209da1dcb6e1 356 timer.start();
jn80842 13:209da1dcb6e1 357 begintime = timer.read_ms();
jn80842 13:209da1dcb6e1 358 pressed == 1;
jn80842 13:209da1dcb6e1 359 }
jn80842 13:209da1dcb6e1 360
jn80842 13:209da1dcb6e1 361 int sn = (colselect + 1)*(rowselect + 1);
jn80842 13:209da1dcb6e1 362 A_in = (sn-1)&2;
jn80842 13:209da1dcb6e1 363 B_in = ((sn-1)/2)%2;
jn80842 13:209da1dcb6e1 364 C_in = ((sn-1)/4)%2;
jn80842 13:209da1dcb6e1 365 D_in = ((sn-1)/8)%2;
jn80842 13:209da1dcb6e1 366 E_in = ((sn-1)/16)%2;
jn80842 13:209da1dcb6e1 367 F_in = ((sn-1)/32)%2;
jn80842 13:209da1dcb6e1 368 volt_buffer[loopcount] = adc.read();
jn80842 13:209da1dcb6e1 369
jn80842 13:209da1dcb6e1 370
jn80842 13:209da1dcb6e1 371 loopcount = loopcount +1;
jn80842 13:209da1dcb6e1 372 } // BREAK THE WHILE SCANBUTTON
jn80842 13:209da1dcb6e1 373
jn80842 13:209da1dcb6e1 374 if (pressed == 1){
jn80842 13:209da1dcb6e1 375 timer.stop();
jn80842 13:209da1dcb6e1 376 endtime = timer.read_ms();
jn80842 13:209da1dcb6e1 377 elapsed = endtime - begintime;
jn80842 13:209da1dcb6e1 378
jn80842 13:209da1dcb6e1 379 DO ENTIRE SCAN STUFF
jn80842 13:209da1dcb6e1 380
jn80842 13:209da1dcb6e1 381 pressed = 0;
jn80842 13:209da1dcb6e1 382 }
jn80842 13:209da1dcb6e1 383
jn80842 13:209da1dcb6e1 384 */