user47797: This seems so simple but I can't solve it. (I'm new to Programming) I do not want to use EEPROM. Just store it and do the math. I strip the Azmuth and Elevation values from a satellite tracker program and need to calculate the difference the satellite has moved to turn the rotors. Here's my efforts so far as requested ...Thanks
/*  Sketch for WXtrack satellite tracking software
 *  VE3COJ Burlington, Ontario, Canada 
 *  Requires COM port and Max 232 from PC
 *  to Serial in on Arduino (Rx)
 * 
 *  Download URL:  http://www.satsignal.eu/software/wxtrack.htm
 *  
 *  Setup in WXtrack: Go to <Tracker menu> <Options> <Select EGIS COM port> <check box XY mode>
 *  Select a Satellite using Manual in Timeframe box. 
 *  Highlight Satellite icon, Use seconds box (third box from left side) to increment satellite.
 *  Use the Sketch Monitor to see Elevation and azimuth reading from Serial port. 
 *  Alternatly, one can use an array to simulate Elevation and Azimuth increments in degrees.
 */


      #include <Stepper.h>
      #include <avr/pgmspace.h>
      #define STEP 50
      #define motorSteps 600      // Number of steps to turn the motor
      #define motorPin1 8
      #define motorPin2 9
      #define motorPin3 10
      #define motorPin4 11

      // 2 EasyDriver boards will be used in final project //


          String readString, read_az, read_el;

          int el_current_store_0;           // elevation ... global value ??
          int el_current_store_1;
          int el_position;                  // final value in degrees to move rotor

          int az_current_store_1;           // azimuth ..... global value ??

       void setup() {


          Serial.begin(9600);
          Serial.println("  AZ & EL "); // so I can keep track of elevation and Azimuth
          Serial.println (" =========");
          Serial.print("");
      }

      void loop() {

           while (Serial.available()) {
              delay(3);  //delay to allow buffer to fill
               if (Serial.available() >0) { 
              char c = Serial.read();  //gets one byte from serial buffer
           readString += c; //makes the string readString
      }
    }

          if (readString.length() >0) {
          //Serial.println(readString); //see what was received from Serial input

          // pull out the number values required... parse the serial output
          // On WXtrack menu, select "Tracker" > "Options" > "EGIS COM" & "XY mode"
          read_az = readString.substring(3, 7);   //get the first 3 to the 6th integers (azmuth)
          read_el = readString.substring(10, 13); //get the next 10 to thee 13th integers (elevation)

         int el_current_store = read_el.toInt();  // Change String el to Integer             
         int az_current_store = read_az.toInt();  // Change String Az to integer

        /* This is an attemp to calculate the difference in degrees the satellite moves. */

         int n1 = el_current_store_0;       // first elevation reading ... store it ... how?
         int n2 = el_current_store_1;       // second elevation reading ... 
         int el_position = (n2 - n1);       // Subtract first from second ... equals how many degrees to turn the rotor


                                           // if result is negative, rotor changes direction

          /* Can't be done as is because the reading gets put in all variables

           * I cannot figure out how to store the number of degrees in memory (Not EEPROM)
           *  EEPROM will burn out eventually, FLASH cannot change values it appears... in docs.
           *  
           * From here:
           * Store first reading from Serial port into memory. 
           * Rotor moves to degrees probably 3 degrees ... read second position (if 4 degrees)
           * Subtract 3 degrees from 4 degrees equals 1 and multiply by variable STEP (200 STEP = 1 degree motor rotation)
           * Get next elevation reading and repeat subtraction... 
           */


           // Print to serial monitor to see results of all values //


           Serial.print("  Elevation = ");
           Serial.println(read_el);

           Serial.print("  Azimuth = ");
           Serial.println(read_az); 

           //Serial.println(el_position);
           Serial.println (" --------next-------");

           Serial.print("");

           readString="";
          }
         }

          /* 1. ========= Send Antenna to 0 degrees / Check for interrup at 0 degrees & Stop ========= 
                ========= Wait for Serial input then goto 2. ========= 

             2. ========= Get Az and El from Serial Port and Start Tracking ==========  

             3. ========= Store (first, second, etc. ) El and AZ ========= 

             4. ========= Get Next El and Az / Subtract from one before El & Az ========= 

             5. ========= Move Antenna to Next Position ======= 

             6. ======== Goto 3. ========= 

             7. ======== If El Equals 0, Goto 1.

                       When El = 90 degrees, (Satellite overhead) Az rotates 180 degrees and 

                       El decreases, coming down to the horizon.

                      When Satellite is off to E or W, elevation does not reach 90 degrees!
         */   


user27653: You have the following global variables declared:
int el_current_store_0;           // elevation ... global value ??
int el_current_store_1;
int el_position;                  // final value in degrees to move rotor

int az_current_store_1;           // azimuth ..... global value ??

But you never put anything into these variables.
Here is your relevant code that attempts to work with these values:
// pull out the number values required... parse the serial output
// On WXtrack menu, select "Tracker" > "Options" > "EGIS COM" & "XY mode"
read_az = readString.substring(3, 7);   //get the first 3 to the 6th integers (azmuth)
read_el = readString.substring(10, 13); //get the next 10 to thee 13th integers (elevation)

int el_current_store = read_el.toInt();  // Change String el to Integer             
int az_current_store = read_az.toInt();  // Change String Az to integer

Above, you are declaring new variables el_current_store and az_current_store and giving them integer values converted from your input string. When you prefix a variable name with int (or any other type) you are declaring a new variable within that scope. In this case, the scope is the if (readString.length() >0) {} block. Once that block ends, those variables don't exist anymore, and every time that block runs, new variables are created there, and destroyed at the end of the block.
/* This is an attemp to calculate the difference in degrees the satellite moves. */

int n1 = el_current_store_0;       // first elevation reading ... store it ... how?
int n2 = el_current_store_1;       // second elevation reading ... 
int el_position = (n2 - n1);       // Subtract first from second ... equals how many degrees to turn the rotor

Above, you declare new variables n1, n2, and el_position. However, you give n1 and n2 whatever was in el_current_store_0 and el_current_store_1, but you have never put any value into those variables, and so they have nothing.
Once that is solved, you also need to take a look at declaring a new variable by the command:
int el_position = (n2 - n1);       // Subtract first from second ... equals how many degrees to turn the rotor

which, because it's in a nearer scope than the global variable of the same name, is used instead of the global. And when the scope block ends, it is destroyed.
You should instead assign the computed value to el_position without making a new variable:
el_position = (n2 - n1);       // Subtract first from second ... equals how many degrees to turn the rotor

(Note, no int in front...)
**EDIT: To actually keep the values for the next loop(), you do have to store them in global (or static) variables. Something like this appears to be what you were going for:
     int el_current_store = read_el.toInt();  // Change String el to Integer             
     int az_current_store = read_az.toInt();  // Change String Az to integer

    /* This is an attemp to calculate the difference in degrees the satellite moves. */

     // Added code below keeps the older value in *_1
     // Puts the newer value in *_0
     el_current_store_1 = el_current_store_0;
     el_current_store_0 = el_current_store;

     az_current_store_1 = az_current_store_0;
     az_current_store_0 = az_current_store;

     int n1 = el_current_store_0;       // first elevation reading ... store it ... how?
     int n2 = el_current_store_1;       // second elevation reading ... 
     int el_position = (n2 - n1);       // Subtract first from second ... equals how many degrees to turn the rotor


47797: <p>This seems so simple but I can't solve it. (I'm new to Programming) I do not want to use EEPROM. Just store it and do the math. I strip the Azmuth and Elevation values from a satellite tracker program and need to calculate the difference the satellite has moved to turn the rotors. Here's my efforts so far as requested ...Thanks</p>

<pre><code>/*  Sketch for WXtrack satellite tracking software
 *  VE3COJ Burlington, Ontario, Canada 
 *  Requires COM port and Max 232 from PC
 *  to Serial in on Arduino (Rx)
 * 
 *  Download URL:  http://www.satsignal.eu/software/wxtrack.htm
 *  
 *  Setup in WXtrack: Go to &lt;Tracker menu&gt; &lt;Options&gt; &lt;Select EGIS COM port&gt; &lt;check box XY mode&gt;
 *  Select a Satellite using Manual in Timeframe box. 
 *  Highlight Satellite icon, Use seconds box (third box from left side) to increment satellite.
 *  Use the Sketch Monitor to see Elevation and azimuth reading from Serial port. 
 *  Alternatly, one can use an array to simulate Elevation and Azimuth increments in degrees.
 */


      #include &lt;Stepper.h&gt;
      #include &lt;avr/pgmspace.h&gt;
      #define STEP 50
      #define motorSteps 600      // Number of steps to turn the motor
      #define motorPin1 8
      #define motorPin2 9
      #define motorPin3 10
      #define motorPin4 11

      // 2 EasyDriver boards will be used in final project //


          String readString, read_az, read_el;

          int el_current_store_0;           // elevation ... global value ??
          int el_current_store_1;
          int el_position;                  // final value in degrees to move rotor

          int az_current_store_1;           // azimuth ..... global value ??

       void setup() {


          Serial.begin(9600);
          Serial.println("  AZ &amp; EL "); // so I can keep track of elevation and Azimuth
          Serial.println (" =========");
          Serial.print("");
      }

      void loop() {

           while (Serial.available()) {
              delay(3);  //delay to allow buffer to fill
               if (Serial.available() &gt;0) { 
              char c = Serial.read();  //gets one byte from serial buffer
           readString += c; //makes the string readString
      }
    }

          if (readString.length() &gt;0) {
          //Serial.println(readString); //see what was received from Serial input

          // pull out the number values required... parse the serial output
          // On WXtrack menu, select "Tracker" &gt; "Options" &gt; "EGIS COM" &amp; "XY mode"
          read_az = readString.substring(3, 7);   //get the first 3 to the 6th integers (azmuth)
          read_el = readString.substring(10, 13); //get the next 10 to thee 13th integers (elevation)

         int el_current_store = read_el.toInt();  // Change String el to Integer             
         int az_current_store = read_az.toInt();  // Change String Az to integer

        /* This is an attemp to calculate the difference in degrees the satellite moves. */

         int n1 = el_current_store_0;       // first elevation reading ... store it ... how?
         int n2 = el_current_store_1;       // second elevation reading ... 
         int el_position = (n2 - n1);       // Subtract first from second ... equals how many degrees to turn the rotor


                                           // if result is negative, rotor changes direction

          /* Can't be done as is because the reading gets put in all variables

           * I cannot figure out how to store the number of degrees in memory (Not EEPROM)
           *  EEPROM will burn out eventually, FLASH cannot change values it appears... in docs.
           *  
           * From here:
           * Store first reading from Serial port into memory. 
           * Rotor moves to degrees probably 3 degrees ... read second position (if 4 degrees)
           * Subtract 3 degrees from 4 degrees equals 1 and multiply by variable STEP (200 STEP = 1 degree motor rotation)
           * Get next elevation reading and repeat subtraction... 
           */


           // Print to serial monitor to see results of all values //


           Serial.print("  Elevation = ");
           Serial.println(read_el);

           Serial.print("  Azimuth = ");
           Serial.println(read_az); 

           //Serial.println(el_position);
           Serial.println (" --------next-------");

           Serial.print("");

           readString="";
          }
         }

          /* 1. ========= Send Antenna to 0 degrees / Check for interrup at 0 degrees &amp; Stop ========= 
                ========= Wait for Serial input then goto 2. ========= 

             2. ========= Get Az and El from Serial Port and Start Tracking ==========  

             3. ========= Store (first, second, etc. ) El and AZ ========= 

             4. ========= Get Next El and Az / Subtract from one before El &amp; Az ========= 

             5. ========= Move Antenna to Next Position ======= 

             6. ======== Goto 3. ========= 

             7. ======== If El Equals 0, Goto 1.

                       When El = 90 degrees, (Satellite overhead) Az rotates 180 degrees and 

                       El decreases, coming down to the horizon.

                      When Satellite is off to E or W, elevation does not reach 90 degrees!
         */   
</code></pre>
 27653: <p>You have the following global variables declared:</p>

<pre><code>int el_current_store_0;           // elevation ... global value ??
int el_current_store_1;
int el_position;                  // final value in degrees to move rotor

int az_current_store_1;           // azimuth ..... global value ??
</code></pre>

<p>But you never put anything into these variables.</p>

<p>Here is your relevant code that attempts to work with these values:</p>

<pre><code>// pull out the number values required... parse the serial output
// On WXtrack menu, select "Tracker" &gt; "Options" &gt; "EGIS COM" &amp; "XY mode"
read_az = readString.substring(3, 7);   //get the first 3 to the 6th integers (azmuth)
read_el = readString.substring(10, 13); //get the next 10 to thee 13th integers (elevation)

int el_current_store = read_el.toInt();  // Change String el to Integer             
int az_current_store = read_az.toInt();  // Change String Az to integer
</code></pre>

<p>Above, you are declaring <em>new</em> variables <code>el_current_store</code> and <code>az_current_store</code> and giving them integer values converted from your input string. When you prefix a variable name with <code>int</code> (or any other type) you are declaring a new variable within that scope. In this case, the scope is the <code>if (readString.length() &gt;0) {}</code> block. Once that block ends, those variables don't exist anymore, and every time that block runs, new variables are created there, and destroyed at the end of the block.</p>

<pre><code>/* This is an attemp to calculate the difference in degrees the satellite moves. */

int n1 = el_current_store_0;       // first elevation reading ... store it ... how?
int n2 = el_current_store_1;       // second elevation reading ... 
int el_position = (n2 - n1);       // Subtract first from second ... equals how many degrees to turn the rotor
</code></pre>

<p>Above, you declare new variables <code>n1</code>, <code>n2</code>, and <code>el_position</code>. However, you give <code>n1</code> and <code>n2</code> whatever was in <code>el_current_store_0</code> and <code>el_current_store_1</code>, but you have <strong>never</strong> put any value into those variables, and so they have nothing.</p>

<p>Once that is solved, you also need to take a look at declaring a new variable by the command:</p>

<pre><code>int el_position = (n2 - n1);       // Subtract first from second ... equals how many degrees to turn the rotor
</code></pre>

<p>which, because it's in a nearer scope than the global variable of the same name, is used instead of the global. And when the scope block ends, it is destroyed.</p>

<p>You should instead assign the computed value to <code>el_position</code> without making a new variable:</p>

<pre><code>el_position = (n2 - n1);       // Subtract first from second ... equals how many degrees to turn the rotor
</code></pre>

<p>(Note, no <code>int</code> in front...)</p>

<p>**EDIT: To actually keep the values for the next <code>loop()</code>, you do have to store them in global (or static) variables. Something like this appears to be what you were going for:</p>

<pre><code>     int el_current_store = read_el.toInt();  // Change String el to Integer             
     int az_current_store = read_az.toInt();  // Change String Az to integer

    /* This is an attemp to calculate the difference in degrees the satellite moves. */

     // Added code below keeps the older value in *_1
     // Puts the newer value in *_0
     el_current_store_1 = el_current_store_0;
     el_current_store_0 = el_current_store;

     az_current_store_1 = az_current_store_0;
     az_current_store_0 = az_current_store;

     int n1 = el_current_store_0;       // first elevation reading ... store it ... how?
     int n2 = el_current_store_1;       // second elevation reading ... 
     int el_position = (n2 - n1);       // Subtract first from second ... equals how many degrees to turn the rotor
</code></pre>
