save the value

Over the last few days I've been reading about for loops, global variables, char, strings and EEPROM. Unfortunately I'm still not finding what I need. It could be I'm just over looking an example and just not seeing what I need.

I'm looking to store a value RAM.

I'm using a rotary encoder in conjunction with a 40x4 LCD to display the position of a object moving on a rail. The position object could be any number between 0 or 10,203 as the object slides along the rail. I'm wanting to save a that number when a button is pushed but I don't want to save it in EEPROM.

Lets just say the number is encoder count is 6,798 how can I set that number aside to be used later?
If some one can point me to an example that I may view it, that would be a huge help.

int RAMstoredNumber;

RAMstoredNumber = 6798;

//now it's in SRAM waiting to used for something:

if (RAMstoredNumber >=5000){
//do something
// then reset it, to 0 for example
RAMstoredNumber = 0;
}

Variables are storage locations in RAM. You just need to declare a 'normal' variable to store your value.

Thank you much.

That looks about what I was coming up with. The only problem is every time I would do such a sketch the number would change with travel. I will play with it some more.

Thanks again.

The only problem is every time I would do such a sketch the number would change with travel.

Why is that a problem? You should explain what you are trying to do, not how you are trying to do it.

I am sorry to keep bugging you guys I feel like Forest Gump. I just cant figure out how to save a number when a pin goes high. Push a button n save a number sounds like a simple idea.

I’m working on a sawmill and I’m using encoders to keep track of the bed position. I will need to save the beginning of the log and the ending of it.

SAButter:
I'm working on a sawmill

PLEASE PLEASE PLEASE

Do your learning on something that can't cause serious personal injury.

Put the sawmill project to one side until such time as you can write your program without needing to ask for advice here about the very basic aspects of programming.

Even when you do know how to write programs don't do anything to a sawmill without first consulting your liability insurers.

...R

I am sorry to keep bugging you guys I feel like Forest Gump. I just cant figure out how to save a number when a pin goes high. Push a button n save a number sounds like a simple idea.

Where is this number that you want to save coming from ?

I have gotten the LCD to display everything I need and rotary encoder position "the saw position" on the bed. I can not figure out how to set a beginning and ending of a log on the bed to work with a for loop. I just cant figure it out for some reason I've looked at dozens of examples.

I got to head to work but I will check back later, you guys have a nice one.

It's starting to sound like you don't understand scope. I'm guessing that you are saving the data in a non-static variable, and the value gets reset when loop() runs again. It's time to post your code.

And to follow Robin's advice. Unless the saw is a scroll saw and the logs are tinker-toy logs.

Lol. I’m not getting something. And don’t worry guys this is a tiny mill for sawing Lincoln logs…

Now keep in mind that I never could figure out how to set a beginning or ending of a log. So I didn’t go any further of trying writing a for loop.

/*-----( Import needed libraries )-----*/
#include <Encoder.h>
#include <Wire.h>  // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>// the pins are A0 ans A1 for serial transmission
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

/*-----( Declare Variables )-----*/

Encoder knobLeft(5, 6);
Encoder knobRight(7, 8);

 int start = 0;
 int sstop = 0; 
 int bedSet = 0;
 int sawSet = 0;
const int bedSetPin = 3;
const int sawSetPin = 4;




long positionRight = -999;
long positionLeft = -999;
void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(115200);  // Used to type in characters

  lcd.begin(20,4);   // initialize the lcd for 20 chars 4 lines, turn on backlight

  lcd.backlight(); // finish with backlight on  
  

long positionRight = -999;
long positionLeft = -999;

//-------- Write characters on the display ------------------
// NOTE: Cursor Position: (CHAR, LINE) start at 0  
  lcd.setCursor(0,0); //Start at character 4 on line 0
  lcd.print("Bed Set");
  lcd.setCursor(0,1);
  lcd.print("Saw Set"); // Print text on 2nd Line
  lcd.setCursor(0,2);
  lcd.print("Start"); //Print 20 characters on 3rd line
  lcd.setCursor(0,3);
  lcd.print("Stop");
  
  pinMode (bedSetPin, INPUT);
  pinMode (sawSetPin, INPUT);
}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  long newLeft, newRight;
  newLeft = knobLeft.read(), newLeft = newLeft / 4;
  newRight = knobRight.read(), newRight = newRight / 4;
  if (newLeft != positionLeft || newRight != positionRight) {
    lcd.setCursor(8,0);
    lcd.print(newLeft);
    lcd.print("    ");
    lcd.setCursor(8,1);
    lcd.print(newRight);
    lcd.print("    ");
    
      bedSet = digitalRead(bedSetPin);


  if (newLeft > newRight) {     
    lcd.setCursor(7, 2), lcd.print("GO");
  }
      else {
    lcd.setCursor(7, 2), lcd.print("  ");
  }
  
    if (newLeft < newRight) {     
    lcd.setCursor(7, 3), lcd.print("STOP");
  }
      else {
    lcd.setCursor(7, 3), lcd.print("    ");
  }
 }

}

Maybe this picture will help with show and tell.

If I wanted to write a for loop to saw the entire length of the bed I can do that but I will be sawing air 60% of the time. Somehow I need a way to set the starting and ending point of each log.

Somehow I need a way to set the starting and ending point of each log.

Advance the saw until it touches the log.
Prompt for the length of the log.
Multiply the length of the log by the number of pulses per foot produced by the encoder.
Save the result in a variable. Let's name the variable targetPulses for this example.
Zero a counter variable, perhaps by reading the input from a pushbuttonbutton.
Start the motor and advance the saw through the log counting the encoder pulses.
Stop advancing the saw when the number of encoder pulses read equals or is greater than targetPulses.
Stop the saw
Move the saw back to the start position.
Zero the pulse counter
Move the saw or log over ready for the next cut
Start cutting and counting again
Repeat until the whole width of the log is cut.