void rotary(){ timeOut = 0; // initialize timeOut flag rotaryLoop: timeOutVal = millis() + rotaryT1; // set a timeout counter presentState = digitalRead(rotaryA); // create a present State value while(digitalRead(rotaryA)==presentState){ // loop until there is a change if(millis() >= timeOutVal){ // check if time Out occurred timeOut = 1; // on condition set time Out flag break; // break from the 'while' loop } if(timeOut == 1) // check if here on a time Out return; // you have a time Out so return to caller } if(digitalRead(rotaryA) == 0){ // On condition you went from a high to low state if(digitalRead(rotaryB) == 0) // check for positive direction rotaryNegative(); // on condition set negative direction else rotaryPositive(); // on condition set positive direction rotaryLimits(); // insure no number limits happened if(runFlag == 1) // check if run state change return; // on condtion escape rotary routine goto rotaryLoop; } } void rotaryPositive(){ switch (curX){ // if here it was a positive direction case line0XC: // cursor position 38 is where "setupOpt' sits on display ++setupOpt; // if here increment the value break; // break out of this switch function case 107: // where the "protoID" and "mode" sits on the display if(setupOpt<2) // if not is MODE setup then increment the "protoID" protoID=protoID+1; // increment else ++modeID; // if here than it is MODE setup so increment break; // you know what this does // F1 positive rotary direction row decode section case 18: // where Frequency 'F1' sits on the display F1=F1+10000; // if here than increment the 10000th position of F1 break; case 24: // where Frequency "F1" sits on the display F1=F1+1000; // if here than increment the 1000th position of F1 break; case 30: F1=F1+100; // if here than increment the 100th position of F1 break; case 36: F1=F1+10; // if here than increment the 10th position of F1 break; case 42: F1=F1+1; // if here than increment the units position of F1 break; case 54: F1=F1+0.1; // if here than increment the tenth position of F1 break; case 60: F1=F1+0.01; // if here than increment the hundredth position of F1 break; case 72: endTime1=endTime1+1000000; // if here than inc the 1000th position of endTime1 second count break; case 78: endTime1=endTime1+100000; // if here than inc the 100th position of endTime1 second count break; case 84: endTime1=endTime1+10000; // if here than inc the 10th position of endTime1 second count break; case 90: endTime1=endTime1+1000; // if here than inc the units position of endTime1 second count break; case 102: if(modeID==2) ++startFreqGrpID; // if here than inc the starting Frequency or Sweep Group ID if(modeID==3) ++startSweepGrpID; // if here then inc the Starting Sweep Group ID break; case 108: // where Duty Cycle 1 sits on the display D1=D1+0.1; // if here than increment the tenth position this duty cycle break; // you know what this does case 114: D1=D1+0.01; // if here than increment the hundredth position of duty break; } // F2 positive rotary direction row decode section switch (curX){ // Now it time to check if Frequency 2 needs updating case 19: // where the Frequency 2 sits on the display F2=F2+10000; // if here increment the 10000th position of F2 break; case 25: F2=F2+1000; // if here increment the 1000th position of F2 break; case 31: F2=F2+100; // if here increment the 100th position of F2 break; case 37: F2=F2+10; // if here increment the 10th position of F2 break; case 43: F2=F2+1; // if here increment the units position of F2 break; case 55: F2=F2+0.1; // if here increment the tenth position of F2 break; case 61: F2=F2+0.01; // if here increment the hundredth position of F2 break; case 79: endTime2=endTime2+60000000; // if here inc the 1000th position of endTime2 time in minutes break; case 85: endTime2=endTime2+6000000; // if here inc the 100th position of endTime2 time in minutes break; case 91: endTime2=endTime2+600000; // if here inc the 10the position of endTime2 time in minutes break; case 97: endTime2=endTime2+60000; // if here inc the units position of endTime2 time in minutes break; case 103: if(modeID==2) ++stopFreqGrpID; // if here inc the starting Frequency or Sweep Group ID if(modeID==3) ++stopSweepGrpID; // if here then inc the Starting Sweep Group ID break; case 109: // where Duty Cycl 2 sits on the display D2=D2+0.1; // if here increment the tenth position break; case 115: D2=D2+0.01; // if here increment the hundredth position break; // get out of this case } // F3 positive rotary direction row decode section switch (curX){ // Now it time to check if Frequency 2 needs updating case 20: // where the Frequency 2 sits on the display F3=F3+10000; // if here increment the 10000th position of F2 break; case 26: F3=F3+1000; // if here increment the 1000th position of F2 break; case 32: F3=F3+100; // if here increment the 100th position of F2 break; case 38: F3=F3+10; // if here increment the 10th position of F2 break; case 44: F3=F3+1; // if here increment the units position of F2 break; case 56: F3=F3+0.1; // if here increment the tenth position of F2 break; case 62: F3=F3+0.01; // if here increment the hundredth position of F2 break; case 82: sweepFreqInc+=1000; // if here inc the 1000th position break; case 88: sweepFreqInc+=100; // if here inc the 100th position break; case 94: sweepFreqInc+=10; // if here inc the 10th position break; case 99: fileNo=fileNo+1; // if here increment the file number break; case 100: sweepFreqInc+=1.0; // if here inc the units position break; case 112: sweepFreqInc+=0.1; // if here inc the fractional tenth position break; case 118: sweepFreqInc+=0.01; // if here inc the fractional hundredth position break; case 79: endTime2=endTime2+60000000; // if here inc the 1000th position of endTime2 time in minutes break; case 85: endTime2=endTime2+6000000; // if here inc the 100th position of endTime2 time in minutes break; case 91: endTime2=endTime2+600000; // if here inc the 10the position of endTime2 time in minutes break; case 97: endTime2=endTime2+60000; // if here inc the units position of endTime2 time in minutes break; case 103: if(modeID==2){ ++stopFreqGrpID;} // if here inc the starting Frequency or Sweep Group ID if(modeID==3){ ++stopSweepGrpID;} // if here then inc the Starting Sweep Group ID break; case 110: // where Duty Cycl 2 sits on the display D3=D3+0.1; // if here increment the tenth position break; case 116:{ D3=D3+0.01; // if here increment the hundredth position break;} // get out of this case } // F4 positive rotary direction row decode section switch (curX){ // Now it time to check if Frequency 2 needs updating case 21: // where the Frequency 2 sits on the display F4=F4+10000; // if here increment the 10000th position of F2 break; case 27: F4=F4+1000; // if here increment the 1000th position of F2 break; case 33: F4=F4+100; // if here increment the 100th position of F2 break; case 39: F4=F4+10; // if here increment the 10th position of F2 break; case 45: F4=F4+1; // if here increment the units position of F2 break; case 57: F4=F4+0.1; // if here increment the tenth position of F2 break; case 63: F4=F4+0.01; // if here increment the hundredth position of F2 break; case 79: endTime2=endTime2+60000000; // if here inc the 1000th position of endTime2 time in minutes break; case 85: endTime2=endTime2+6000000; // if here inc the 100th position of endTime2 time in minutes break; case 91: endTime2=endTime2+600000; // if here inc the 10the position of endTime2 time in minutes break; case 97: endTime2=endTime2+60000; // if here inc the units position of endTime2 time in minutes break; case 103: if(modeID==2) ++stopFreqGrpID; // if here inc the starting Frequency or Sweep Group ID if(modeID==3) ++stopSweepGrpID; // if here then inc the Starting Sweep Group ID break; case 111: // where Duty Cycl 2 sits on the display D4=D4+0.1; // if here increment the tenth position break; case 117: D4=D4+0.01; // if here increment the hundredth position break; // get out of this case } } void rotaryNegative(){ switch (curX){ // use switch to decided what to do case line0XC: // this is where the "setupOpt" sits on the display --setupOpt; // if here decrement the setup Option break; // get out of this switch function case 107: // where "mode" and "protoID" sits on the display if(setupOpt<2) // on condition than not a mode change protoID=protoID-1; // if here decrement the "protoID" else --modeID; // if here than decrement the "mode" break; // you know what this does // F1 negative rotary direction row decode section case 18: // this is where Frequency 1 F1 sits on the display if(F1>=10000) F1=F1-10000; // if here decrement the 10000th position of F1 break; case 24: if(F1>=1000) F1=F1-1000; // if here decrement the 1000th position of F1 break; case 30: if(F1>=100) F1=F1-100; // if here decrement the 100th position of F1 break; case 36: if(F1>=10) F1=F1-10; // if here decrement the 10th position of F1 break; case 42: if(F1>=1) F1=F1-1; // if here decrement the units position of F1 break; case 54: F1=F1-0.1; // if here decrement the tenth position of F1 break; case 60: F1=F1-0.01; // if here decrement the hundredth position of F1 break; case 72: endTime1=endTime1-1000000; // if here dec 1000th position of endTime1 Time in seconds break; case 78: endTime1=endTime1-100000; // if here dec 100th position of endTime1 Time in seconds break; case 84: endTime1=endTime1-10000; // if here dec 10th position of endTime1 Time in seconds break; case 90: endTime1=endTime1-1000; // if here dec units position of endTime Time in seconds break; case 102: if(modeID==2) --startFreqGrpID; // if here than inc the starting Frequency or Sweep Group ID if(modeID==3) --startSweepGrpID; // if here then inc the Starting Sweep Group ID break; case 108: // where Duty Cycl 1 sits on the display D1=D1-0.1; // if here decrement the tenth position of the duty cycle break; case 114: D1=D1-0.01; // if here decrement the hundredth position of duty cycle break; } // F2 negative rotary direction row decode section switch (curX){ // do the same as above for Frequency 2 F2 case 19: // where Frequency 2 F2 sits on the display if(F2>=10000) F2=F2-10000; // if here dec Frequency 2 10000th position break; case 25: if(F2>=1000) F2=F2-1000; // if here dec Frequency 2 1000th position break; case 31: if(F2>=100) F2=F2-100; // if here dec Frequency 2 100th position break; case 37: if(F2>=10) F2=F2-10; // if here dec Frequency 2 10th position break; case 43: if(F2>=1) F2=F2-1; // if here dec Frequency 2 units position break; case 55: F2=F2-0.1; // if here dec Frequency 2 tenth position break; case 61: F2=F2-0.01; // if here dec Frequency 2 hundredth position break; case 79: endTime2=endTime2-60000000; // if here dec endTime2 1000th position in minutes break; case 85: endTime2=endTime2-6000000; // if here dec endTime2 100th position in minutes break; case 91: endTime2=endTime2-600000; // if here dec endTime2 10th position in minutes break; case 97: endTime2=endTime2-60000; // if here dec endTime2 units position in minutes break; case 103: if(modeID==2) --stopFreqGrpID; // if here than inc the starting Frequency or Sweep Group ID if(modeID==3) --stopSweepGrpID; // if here then inc the Starting Sweep Group ID break; case 109: // this is where Duty Cycle 2 sits on the display D2=D2-0.1; // if here decrement the tenth position of Duty Cycle 2 break; case 115: D2=D2-0.01; // if here decrement the hundredth position break; } // F3 negative rotary direction row decode section switch (curX){ // Now it time to check if Frequency 3 needs updating case 20: // where the Frequency 3 sits on the display F3=F3-10000; // if here dec the 10000th position of F3 break; case 26: F3=F3-1000; // if here dec the 1000th position of F3 break; case 32: F3=F3-100; // if here dec the 100th position of F3 break; case 38: F3=F3-10; // if here dec the 10th position of F3 break; case 44: F3=F3-1; // if here dec the units position of F3 break; case 56: F3=F3-0.1; // if here dec the tenth position of F3 break; case 62: F3=F3-0.01; // if here dec the hundredth position of F3 break; case 82: sweepFreqInc-=1000; // if here inc the 1000th position break; case 88: sweepFreqInc-=100; // if here inc the 100th position break; case 94: sweepFreqInc-=10; // if here inc the 10th position break; case 99: fileNo=fileNo-1; // if here decrement the file number break; case 100: sweepFreqInc-=1.0; // if here inc the units position break; case 112: sweepFreqInc-=0.1; // if here inc the fractional tenth position break; case 118: sweepFreqInc-=0.01; // if here inc the fractional hundredth position break; case 79: endTime2=endTime2-60000000; // if here dec the 1000th position of endTime2 time in minutes break; case 85: endTime2=endTime2-6000000; // if here dec the 100th position of endTime2 time in minutes break; case 91: endTime2=endTime2-600000; // if here dec the 10the position of endTime2 time in minutes break; case 97: endTime2=endTime2-60000; // if here dec the units position of endTime2 time in minutes break; case 103: if(modeID==2) --stopFreqGrpID; // if here dec the starting Frequency or Sweep Group ID if(modeID==3) --stopSweepGrpID; // if here then dec the Starting Sweep Group ID break; case 110: // where Duty Cycl 3 sits on the display D3=D3-0.1; // if here dec the tenth position break; case 116: D3=D3-0.01; // if here dec the hundredth position break; // get out of this case } // F4 negative rotary direction row decode section switch (curX){ // Now it time to check if Frequency 2 needs updating case 21: // where the Frequency 2 sits on the display F4=F4-10000; // if here increment the 10000th position of F2 break; case 27: F4=F4-1000; // if here increment the 1000th position of F2 break; case 33: F4=F4-100; // if here increment the 100th position of F2 break; case 39: F4=F4-10; // if here increment the 10th position of F2 break; case 45: F4=F4-1; // if here increment the units position of F2 break; case 57: F4=F4-0.1; // if here increment the tenth position of F2 break; case 63: F4=F4-0.01; // if here increment the hundredth position of F2 break; case 79: endTime2=endTime2+60000000; // if here inc the 1000th position of endTime2 time in minutes break; case 85: endTime2=endTime2+6000000; // if here inc the 100th position of endTime2 time in minutes break; case 91: endTime2=endTime2+600000; // if here inc the 10the position of endTime2 time in minutes break; case 97: endTime2=endTime2+60000; // if here inc the units position of endTime2 time in minutes break; case 103: if(modeID==2) ++stopFreqGrpID; // if here inc the starting Frequency or Sweep Group ID if(modeID==3) ++stopSweepGrpID; // if here then inc the Starting Sweep Group ID break; case 111: // where Duty Cycl 2 sits on the display D4=D4-0.1; // if here increment the tenth position break; case 117: D4=D4-0.01; // if here increment the hundredth position break; // get out of this case } } void rotaryLimits(){ if(setupOpt>200) // This can be no lower than 0 setupOpt=0; // if here make it a zero if(setupOpt>5) // check if greater than 5 setupOpt=5; // on condition make it a 5 if(protoID<1) // This can be no lower than 1 protoID=protoIDlast; // if here make it a 1 if(protoID>protoIDlast) // This can be no higher than 50t protoID=1; // if here make it a 1 if(modeID<1) // This can be no lower than 1 modeID=1; // if here make it a 1 if(modeID>3) // This can be no higher than 3 modeID=3; // if here make it a 3 if(startFreqGrpID<1) // This can be no lower than 1 startFreqGrpID=protoIDlast; // if here make it a 1 if(startFreqGrpID>protoIDlast) // This can be no higher than 50 startFreqGrpID=1; // if here make it a 50 if(stopFreqGrpID<1) // This can be no lower than 1 stopFreqGrpID=protoIDlast; // if here make it a 1 if(stopFreqGrpID>protoIDlast) // This can be no higher than 50 stopFreqGrpID=1; // if here make it a 50 if(startSweepGrpID<1) // This can be no lower than 1 startSweepGrpID=protoIDlast; // if here make it a 1 if(startSweepGrpID>protoIDlast) // This can be no higher than 50 startSweepGrpID=1; // if here make it a 50 if(stopSweepGrpID<1) // This can be no lower than 1 stopSweepGrpID=protoIDlast; // if here make it a 1 if(stopSweepGrpID>protoIDlast)// This can be no higher than 50 stopSweepGrpID=1; // if here make it a 50 if(sweepFreqInc>9999.99) // if it reached limit cycle to zero sweepFreqInc=0.00; if(sweepFreqInc<0.00) // if it less than 0 cycle to limit sweepFreqInc=9999.99; if(F1>50000.00) // Frequency 1 can be no higher than 50K F1=50000.00; // if higher make it 50K if(F1<0.01) // Frequency 1 can be no lower than 1.00 hertz F1=0.01; // if lower make it 1.00 hertz if(D1>1.00) // Duty Cycle 1 can be no higher than 100% D1=1.00; // if higher make it 100% if(D1<0.00) // Duty Cycle 1 can be no lower than 0% D1=0.00; // if lower make it 0% if(F2>50000.00) // Frequency 2 can be no higher than 50.00K F2=50000.00; // if higher make it 50k if(F2<0.01) // Frequency 2 can be no lower than .01 hertz F2=0.01; // if lower make it .01 hertz if(D2>1.00) // Duty Cycle 2 can be no higher than 100% D2=1.00; // if higher than make it 100% if(D2<0.00) // Duty Cycle 2 can be no lower than 0% D2=0.00; // if lower than make it 0% if(F3>50000.00) // Frequency 3 can be no higher than 50K F3=50000.00; // if higher make it 50k if(F3<0.01) // Frequency 3 can be no lower than .01 hertz F3=0.01; // if lower make it .01 hertz if(D3>1.00) // Duty Cycle 3 can be no higher than 100% D3=1.00; // if higher than make it 100% if(D3<0.00) // Duty Cycle 3 can be no lower than 0% D3=0.00; // if lower than make it 0% if(F4>50000.00) // Frequency 4 can be no higher than 50K F4=50000.00; // if higher make it 50k if(F4<0.01) // Frequency 4 can be no lower than .01 hertz F4=0.01; // if lower make it .01 hertz if(D4>1.00) // Duty Cycle 4 can be no higher than 100% D4=1.00; // if higher than make it 100% if(D4<0.00) // Duty Cycle 4 can be no lower than 0% D4=0.00; // if lower than make it 0% if(endTime1<1000) // endTime1 can be lower than 1 seconds endTime1=500; // make it 1/2 second if(endTime1>1000){ // make sure fraction of a second are removed endTime1/=1000; // integer math will remove and fractions endTime1*=1000;} // restore to whole integer second(s) number if(endTime1>9999000) // endTime can be no higher than 9999 second endTime1=1000; // if here make it cycle around to 1 second if(endTime2<60000) // endTime1 can be lower than 1 minute endTime2=30000; // if here make it make 30 seconds = 1/2 minute if(endTime2>60000){ // make sure fraction minutes are removed endTime2/=60000; // integer math will remove any fractions endTime2*=60000;} // restore to whole INTEGER minute(s) number if(endTime2>599940000) // endTime can be no larger than 9999 minutes endTime2=60000; // if here make it 1 minute if(fileNo>9) fileNo=0; if(fileNo<0) fileNo=9; change=1; // indicate there has be a frequency or duty change }