int req = 5; //mic REQ line goes to pin 5 through q1 (arduino high pulls request line low) int dat = 2; //mic Data line goes to pin 2 int clk = 3; //mic Clock line goes to pin 3 int i = 0; int j = 0; int k = 0; int wave; char* error = 0; byte a; float mm; char* family; char* menu; int minnum; int maxnum; float maxmm; int maxl; int staticl; int staticl5; int staticl4; int staticl3; float jump; float range; byte mydata[14]; long num; int gearFamily; int c0 = 0; int c1 = 0; // Menu button const int buttonPin = 4; // the pin that the pushbutton is attached to int buttonPushCounter = 1; // counter for the number of button presses int buttonState = 0; // current state of the button int lastButtonState = 0; // previous state of the button // Average button const int avgPin = 6; // switch is connected to pin 6 int avgVal; // variable for reading the pin status int avgVal2; // variable for reading the delayed status int avgButtonState = 0; // variable to hold the button state int sampleState = 0; // Which sample am I taking (1 of 3)? long m1=0; long m2=0; long m3=0; int samplel1=0; int samplel2=0; int samplel3=0; int sampleAvgl=0; void setup() { Serial3.begin(9600); pinMode(req, OUTPUT); pinMode(clk, INPUT); pinMode(dat, INPUT); digitalWrite(clk, HIGH); // enable internal pull ups digitalWrite(dat, HIGH); // enable internal pull ups digitalWrite(req,LOW); // set request at LOW // initialize the button pin as a input: pinMode(buttonPin, INPUT); pinMode(avgPin, INPUT); // Set the switch pin as input avgButtonState = digitalRead(avgPin); // read the initial state } void loop() { // read menu button // read the pushbutton input pin: buttonState = digitalRead(buttonPin); // compare the buttonState to its previous state if (buttonState != lastButtonState) { // clearScreen(); // if the state has changed, increment the counter if (buttonState == LOW) { // if the current state is HIGH then the button // went from off to on: buttonPushCounter++; // clearScreen(); } } // save the current state as the last state, //for next time through the loop lastButtonState = buttonState; if (buttonPushCounter == 4) { buttonPushCounter = 1; } gearFamily = buttonPushCounter; // gearFamily = 1; // get data from mic // { digitalWrite(req, HIGH); // generate set request for( i = 0; i < 13; i++ ) { k = 0; for (j = 0; j < 4; j++) { while( digitalRead(clk) == LOW) { } // hold until clock is high while( digitalRead(clk) == HIGH) { } // hold until clock is low bitWrite(k, j, (digitalRead(dat) & 0x1)); // read data bits, and reverse order ) } // extract data mydata[i] = k; // sign = mydata[4]; // decimal = mydata[11]; // units = mydata[12]; } // assemble measurement from bytes char buf[7]; for(int lp=0;lp<6;lp++) buf[lp]=mydata[lp+5]+'0'; buf[6]=0; num=atol(buf); //assembled measurement, no decimal place added // Serial.println(num); // test gears if (gearFamily == 1) { // do webster pump family = "Webster"; menu = "Webster Sort"; wave = 3; //A = 1; uvga("A", 1); if (num <= 2289) { family = "Below W 2M"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B = 1; uvga("B", 1); } if (num >= 2290 && num <=2330) { family = "Webster 2M"; minnum = 2290; maxnum = 2330; maxmm = 2.330; maxl = 100; range = .003; jump = .004; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B = 2; uvga("B", 2); } if (num >= 2331 && num <=2919) { family = "W 2M <-> W M34"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=3; uvga("B", 3); } if (num >= 2920 && num <=2970) { family = "Webster M34"; minnum = 2920; maxnum = 2970; maxmm = 2.970; maxl = 200; range = .003; jump = .004; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=4; uvga("B", 4); } if (num >= 2971 && num <=6329) { family = "W M34 <-> W M17"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=5; uvga("B", 5); } if (num >= 6330 && num <=6370) { family = "Webster M17"; minnum = 6330; maxnum = 6370; maxmm = 6.370; maxl = 300; range = .003; jump = .004; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=6; uvga("B", 6); } if (num >= 6371) { family = "Over W M17"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=7; uvga("B", 7); } } else if (gearFamily == 2) { // do j/h pump family="J/H Pump"; menu = "J/H Sort"; wave = 4; //A=2; uvga("A", 2); if (num <= 4476) { family = "Below J/H 180"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=1; uvga("B", 1); } if (num >= 4477 && num <=4572) { family = "J/H 180"; minnum = 4477; maxnum = 4572; maxmm = 4.572; maxl = 50; range = .007; jump = .008; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=2; uvga("B", 2); } if (num >= 4573 && num <=7037) { family = "JH180 <-> JH280"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=3; uvga("B", 3); } if (num >= 7038 && num <=7133) { family = "J/H 280"; minnum = 7038; maxnum = 7133; maxmm = 7.133; maxl = 80; range = .007; jump = .008; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=4; uvga("B", 4); } if (num >= 7134 && num <=8324) { family = "JH280 <-> JH335"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=5; uvga("B", 5); } if (num >= 8325 && num <=8641) { family = "J/H 335/340"; minnum = 8325; maxnum = 8641; maxmm = 8.641; maxl = 181; range = .007; jump = .008; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=6; uvga("B", 6); } if (num >= 8642 && num <=10907) { family = "JH335 <-> JH437"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=7; uvga("B", 7); } if (num >= 10908 && num <=11099) { family = "J/H 437"; minnum = 10908; maxnum = 11099; maxmm = 11.099; maxl = 280; range = .007; jump = .008; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=8; uvga("B", 8); } if (num >= 11100 && num <=12044) { family = "JH437 <-> JH484"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=9; uvga("B", 9); } if (num >= 12045 && num <=12300) { family = "J/H 484"; minnum = 12045; maxnum = 12300; maxmm = 12.300; maxl = 380; range = .007; jump = .008; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=10; uvga("B", 10); } if (num >= 12301 && num <=14088) { family = "JH484 <-> JH562"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=11; uvga("B", 11); } if (num >= 14089 && num <=14312) { family = "J/H 562"; minnum = 14089; maxnum = 14312; maxmm = 14.312; maxl = 484; range = .007; jump = .008; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=12; uvga("B", 12); } if (num >= 14313 && num <=18868) { family = "JH562 <-> JH750"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=13; uvga("B", 13); } if (num >= 18869 && num <=19060) { family = "J/H 750"; minnum = 18869; maxnum = 19060; maxmm = 19.060; maxl = 580; range = .007; jump = .008; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=14; uvga("B", 14); } if (num >= 19061) { family = "Over J/H 750"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=15; uvga("B", 15); } } else if (gearFamily == 3) { // do minipump family="Mini Pump"; menu = "MP Sort"; wave = 3; //A=3; uvga("A", 3); if (num <= 5041) { family = "Below MP200"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=1; uvga("B", 1); } if (num >= 5042 && num <=5109) { family = "Mini Pump 200"; minnum = 5042; maxnum = 5109; maxmm = 5.109; maxl = 50; range = .003; jump = .004; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=2; uvga("B", 2); } if (num >= 5110 && num <=5809) { family = "MP200 <-> MP230"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=3; uvga("B", 3); } if (num >= 5810 && num <=5861) { family = "Mini Pump 230"; minnum = 5810; maxnum = 5861; maxmm = 5.861; maxl = 77; range = .003; jump = .004; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=4; uvga("B", 4); } if (num >= 5862 && num <=7061) { family = "MP230 <-> MP280"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=5; uvga("B", 5); } if (num >= 7062 && num <=7129) { family = "Mini Pump 280"; minnum = 7062; maxnum = 7129; maxmm = 7.129; maxl = 107; range = .003; jump = .004; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=6; uvga("B", 6); } if (num >= 7130 && num <=8575) { family = "MP280 <-> MP340"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=7; uvga("B", 7); } if (num >= 8576 && num <=8699) { family = "Mini Pump 340"; minnum = 8576; maxnum = 8699; maxmm = 8.699; maxl = 140; range = .003; jump = .004; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=8; uvga("B", 8); } if (num >= 8700 && num <=9889) { family = "MP340 <-> MP390"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=9; uvga("B", 9); } if (num >= 9890 && num <=9997) { family = "Mini Pump 390"; minnum = 9890; maxnum = 9997; maxmm = 9.997; maxl = 176; range = .003; jump = .004; staticl = convert(); average(); staticl5 = staticl - 5; staticl4 = staticl - 4; //staticl3 = staticl - 3; staticl3 = staticl + 3; //B=10; uvga("B", 10); } if (num >= 9998) { family = "Over MP390"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=11; uvga("B", 11); } } else if (gearFamily == 4) { // do webster pump match family = "Webster"; menu = "Webster Match"; wave = 3; //A=4; uvga("A", 4); if (num <= 2289) { family = "Below W 2M"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=1; uvga("B", 1); } if (num >= 2290 && num <=2330) { family = "Webster 2M"; minnum = 2290; maxnum = 2330; maxmm = 2.330; maxl = 100; range = .003; jump = .004; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=2; uvga("B", 2); } if (num >= 2331 && num <=2919) { family = "W 2M <-> W M34"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=3; uvga("B", 3); } if (num >= 2920 && num <=2970) { family = "Webster M34"; minnum = 2920; maxnum = 2970; maxmm = 2.970; maxl = 200; range = .003; jump = .004; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=4; uvga("B", 4); } if (num >= 2971 && num <=6329) { family = "W M34 <-> W M17"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=5; uvga("B", 5); } if (num >= 6330 && num <=6370) { family = "Webster M17"; minnum = 6330; maxnum = 6370; maxmm = 6.370; maxl = 300; range = .003; jump = .004; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=6; uvga("B", 6); } if (num >= 6371) { family = "Over W M17"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=7; uvga("B", 7); } } else if (gearFamily == 5) { // do j/h pump family="J/H Pump"; menu = "J/H Match"; wave = 4; //A=5; uvga("A", 5); if (num <= 4476) { family = "Below J/H 180"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=1; uvga("B", 1); } if (num >= 4477 && num <=4572) { family = "J/H 180"; minnum = 4477; maxnum = 4572; maxmm = 4.572; maxl = 50; range = .007; jump = .008; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=2; uvga("B", 2); } if (num >= 4573 && num <=7037) { family = "JH180 <-> JH280"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=3; uvga("B", 3); } if (num >= 7038 && num <=7133) { family = "J/H 280"; minnum = 7038; maxnum = 7133; maxmm = 7.133; maxl = 80; range = .007; jump = .008; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=4; uvga("B", 4); } if (num >= 7134 && num <=8324) { family = "JH280 <-> JH335"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=5; uvga("B", 5); } if (num >= 8325 && num <=8641) { family = "J/H 335/340"; minnum = 8325; maxnum = 8641; maxmm = 8.641; maxl = 181; range = .007; jump = .008; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=6; uvga("B", 6); } if (num >= 8642 && num <=10907) { family = "JH335 <-> JH437"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=7; uvga("B", 7); } if (num >= 10908 && num <=11099) { family = "J/H 437"; minnum = 10908; maxnum = 11099; maxmm = 11.099; maxl = 280; range = .007; jump = .008; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=8; uvga("B", 8); } if (num >= 11100 && num <=12044) { family = "JH437 <-> JH484"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=9; uvga("B", 9); } if (num >= 12045 && num <=12300) { family = "J/H 484"; minnum = 12045; maxnum = 12300; maxmm = 12.300; maxl = 380; range = .007; jump = .008; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=10; uvga("B", 10); } if (num >= 12301 && num <=14088) { family = "JH484 <-> JH562"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=11; uvga("B", 11); } if (num >= 14089 && num <=14312) { family = "J/H 562"; minnum = 14089; maxnum = 14312; maxmm = 14.312; maxl = 484; range = .007; jump = .008; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=12; uvga("B", 12); } if (num >= 14313 && num <=18868) { family = "JH562 <-> JH750"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=13; uvga("B", 13); } if (num >= 18869 && num <=19060) { family = "J/H 750"; minnum = 18869; maxnum = 19060; maxmm = 19.060; maxl = 580; range = .007; jump = .008; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=14; uvga("B", 14); } if (num >= 19061) { family = "Over J/H 750"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=15; uvga("B", 15); } } else if (gearFamily == 6) { // do minipump family="Mini Pump"; menu = "MP Match"; wave = 3; //A=6; uvga("A", 6); if (num <= 5402) { family = "Below MP200"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=1; uvga("B", 1); } if (num >= 5042 && num <=5109) { family = "Mini Pump 200"; minnum = 5042; maxnum = 5109; maxmm = 5.109; maxl = 50; range = .003; jump = .004; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=2; uvga("B", 2); } if (num >= 5110 && num <=5809) { family = "MP200 <-> MP230"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=3; uvga("B", 3); } if (num >= 5810 && num <=5861) { family = "Mini Pump 230"; minnum = 5810; maxnum = 5861; maxmm = 5.861; maxl = 77; range = .003; jump = .004; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=4; uvga("B", 4); } if (num >= 5862 && num <=7061) { family = "MP230 <-> MP280"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=5; uvga("B", 5); } if (num >= 7062 && num <=7129) { family = "Mini Pump 280"; minnum = 7062; maxnum = 7129; maxmm = 7.129; maxl = 107; range = .003; jump = .004; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=6; uvga("B", 6); } if (num >= 7130 && num <=8575) { family = "MP280 <-> MP340"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=7; uvga("B", 7); } if (num >= 8576 && num <=8699) { family = "Mini Pump 340"; minnum = 8576; maxnum = 8699; maxmm = 8.699; maxl = 140; range = .003; jump = .004; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=8; uvga("B", 8); } if (num >= 8700 && num <=9889) { family = "MP340 <-> MP390"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=9; uvga("B", 9); } if (num >= 9890 && num <=9997) { family = "Mini Pump 390"; minnum = 9890; maxnum = 9997; maxmm = 9.997; maxl = 176; range = .003; jump = .004; staticl = convert(); // average(); sampleAvgl = hold(); staticl5 = staticl - 5; staticl4 = staticl - 4; staticl3 = staticl - 3; // staticl3 = staticl + 3; //B=10; uvga("B", 10); } if (num >= 9998) { family = "Over MP390"; staticl = 0; staticl5 = 0; staticl4 = 0; staticl3 = 0; //B=11; uvga("B", 11); } } else if (gearFamily == 7){ // do instructions family = " "; menu = "Instructions"; //A=7; uvga("A", 7); } digitalWrite(req,LOW); error=0; // delay(25); //sendText(22, 05, 3, 255, 255, family); //sendText(22, 03, 3, 255, 255, menu); // } if (gearFamily >= 1 && gearFamily <= 3) { // average //sendDesc(15, 07, 03, 255, 255, "Static"); //sendDesc(35, 07, 03, 255, 255, "Moveable"); // sendData(17, 9, 3, 255, 255, staticl); uvga("E", staticl); // sendData(37, 9, 3, 255, 255, staticl3); uvga("F", staticl3); //sendText(15, 20, 03, 255, 255, "Static"); //sendText(35, 20, 03, 255, 255, "Moveable"); } if (gearFamily >= 4 && gearFamily <= 6) { // match if (gearFamily !=5){ //sendDesc(13, 7, 3, 255, 255, "Moveable 3450"); } //sendDesc(35, 7, 3, 255, 255, "Moveable 1725"); //sendText(15, 20, 3, 255, 255, "Hold"); //sendText(35, 20, 3, 255, 255, "Mic"); int sampleAvg3 = sampleAvgl - 3; int sampleAvg5 = sampleAvgl - 5; if (staticl <= sampleAvg3 && staticl >= sampleAvg5 && staticl3 <= maxl){ //Green c0 = 7; c1 = 224; //sendText(10, 24, 3, c0, c1, " "); //sendText(35, 24, 3, c0, c1, " "); } else { //Red c0 = 248; c1 = 0; //sendText(10, 24, 3, c0, c1, "Reject Bin"); //sendText(35, 24, 3, c0, c1, family); } //sendData(36, 22, 3, c0, c1, staticl); } if (gearFamily == 7) { //sendText(10, 6, 3, 255, 255, "1. Push and hold the red button on the"); //sendText(13, 7, 3, 255, 255, "micrometer to change menu choices."); //sendText(10, 12, 3, 255, 255, "2. Push and hold (1 second) the floor"); //sendText(13, 13, 3, 255, 255, "button to set a sample or hold number."); //sendText(10, 18, 3, 255, 255, "3. Insert some instructions explaining"); //sendText(13, 19, 3, 255, 255, "the use of Sort and Match."); //B=1; uvga("B", 1); } } // convert mm to lindy numbers int convert() { mm = (float)num/1000; float formula = round((((maxmm-(range/2.000))-mm)/jump)); int f; f = (int)formula; int lindy = maxl-f; return lindy; } // Take and display averages void average(){ avgVal = digitalRead(avgPin); // read input value and store it in val // delay(10); // 10 milliseconds is a good amount of time // avgVal2 = digitalRead(avgPin); // read the input again to check for bounces // if (avgVal == avgVal2) { // make sure we got 2 consistant readings! if (avgVal != avgButtonState) { // the button state has changed! if (avgVal == LOW) { // check if the button is pressed if (sampleState == 0) { // No samples sampleState++; // reset sample m1=0; m2=0; m3=0; uvga("G", 0); uvga("H", 0); uvga("I", 0); uvga("N", 0); uvga("O", 0); } else { if (sampleState == 1) { // sampleState++; // Take 1st sample m1=num; // Serial.println(num); // convert m1 to samplel1 and display // samplel1=convert(); //sendText(17, 15, 03, 255, 255, "S1"); uvga("G", 1); // sendData(17, 15, 03, 255, 255, m1); } else { if (sampleState == 2) { // sampleState++; // Take 2nd sample m2=num; // Serial.println(num); // convert m2 to samplel2 and display // samplel2=convert(); //sendText(27, 15, 03, 255, 255, "S2"); uvga("H", 1); // sendData(27, 15, 03, 255, 255, m2); } else { if (sampleState == 3) { // sampleState = 0; // take 3rd sample and calc avg m3=num; // Serial.println(num); // convert m3 to samplel3 and display // samplel3=convert(); //sendText(37, 15, 03, 255, 255, "S3"); uvga("I", 1); num=(m1+m2+m3)/3; // convert mAvg to sampleAvgl and display sampleAvgl=convert(); if ((m1num+wave) || (m2num+wave) || (m3num+wave)) { //Red c0 = 248; c1 = 0; //sendText(10, 24, 3, c0, c1, "Reject Bin"); uvga("N", 1); //sendText(35, 24, 3, c0, c1, family); } else { //Green c0 = 7; c1 = 224; } //sendData(16, 22, 03, c0, c1, sampleAvgl); uvga("L", sampleAvgl); //sendData(36, 22, 03, c0, c1, sampleAvgl +3); uvga("M", sampleAvgl +3); } // } } } } } avgButtonState = avgVal; // save the new state in our variable } } // Take and display hold int hold(){ avgVal = digitalRead(avgPin); // read input value and store it in val // delay(10); // 10 milliseconds is a good amount of time // avgVal2 = digitalRead(avgPin); // read the input again to check for bounces // if (avgVal == avgVal2) { // make sure we got 2 consistant readings! if (avgVal != avgButtonState) { // the button state has changed! if (avgVal == LOW) { // check if the button is pressed if (sampleState == 0) { // No samples sampleState++; // set sampleState to 1 for next pass m1=0; m2=0; m3=0; uvga("G", 0); uvga("H", 0); uvga("I", 0); uvga("N", 0); uvga("O", 0); //sendText(17, 16, 03, 255, 255, " "); //sendText(27, 16, 03, 255, 255, " "); //sendText(37, 16, 03, 255, 255, " "); //sendText(17, 22, 03, 255, 255, " "); //sendText(37, 22, 03, 255, 255, " "); //sendText(10, 24, 3, c0, c1, " "); //sendText(35, 24, 3, c0, c1, " "); } else { if (sampleState == 1) { // sampleState++; // Take 1st sample m1=num; // convert m1 to samplel1 and display // samplel1=convert(); //sendText(17, 16, 03, 255, 255, "S1"); uvga("G", 1); } else { if (sampleState == 2) { // sampleState++; // Take 2nd sample m2=num; // convert m2 to samplel2 and display // samplel2=convert(); //sendText(27, 16, 03, 255, 255, "S2"); uvga("H", 1); } else { if (sampleState == 3) { // sampleState = 0; // Reset samples m3=num; // convert m3 to samplel3 and display // samplel3=convert(); //sendText(37, 16, 03, 255, 255, "S3"); uvga("I", 1); num=(m1+m2+m3)/3; // convert mAvg to sampleAvgl and display sampleAvgl=convert(); if ((m1num+wave) || (m2num+wave) || (m3num+wave)) { //Red c0 = 248; c1 = 0; //sendText(10, 24, 3, c0, c1, "Reject Bin"); uvga("N", 1); //sendText(35, 24, 3, c0, c1, family); } else { //Green c0 = 7; c1 = 224; } // replaceColor(0, 180, 1, 84, 1, 14, 1, 129, 0, 0, 0, 0); // replaceColor(1, 164, 1, 84, 1, 254, 1, 129, 0, 0, 0, 0); if (gearFamily != 5){ //sendData(16, 9, 03, c0, c1, sampleAvgl - 5); uvga("E", sampleAvgl - 5); //sendData(22, 9, 03, c0, c1, sampleAvgl - 4); uvga("P", sampleAvgl - 4); } //sendData(36, 9, 03, c0, c1, sampleAvgl - 3); uvga("F", sampleAvgl - 3); //sendData(16, 22, 03, c0, c1, sampleAvgl); uvga("L", sampleAvgl); // sendData(36, 22, 03, c0, c1, sampleAvgl +3); // replaceColor(0, 180, 1, 84, 1, 14, 1, 129, 0, 0, 0, 0); // replaceColor(1, 164, 1, 84, 1, 254, 1, 129, 0, 0, 0, 0); } } // } } } } // } avgButtonState = avgVal; // save the new state in our variable // return (sampleAvgl); } } int uvga(char* x, int y){ Serial3.print("$"); Serial3.print(x); //Serial3.println(num, DEC); Serial3.println(y, DEC); }