73Views3Replies

Author Options:

Is there a way to change the value of a variable and keep it afterwards? Arduino Answered

Hello everyone,

I don't really know if this is possible, I am using processing, arduino and a force sensitive resistor to control a servo and I want to change the value of a variable and then if I reset the arduino, it will kept the new value. Is there anyway to do this?

This is the part of my code I want to change.


void fsrMovement(){
        int maxforce= 1023;  // THIS IS THE VARIABLE

        if(Serial.available()){  // SERIAL AVAILABLE TO USE WITH PROCESSING
        maxforce = Serial.read();
        }
        force = analogRead(FSR);  // Reads the FSR

        Serial.print("Force sensor reading = ");
        Serial.println(force); // This will print the raw force value
        int pos = map(force, 0, maxforce, 0, 175); // Scales the force reading to degrees for servo control
        Serial.print("servomotor degrees = ");
        Serial.println(pos); // This will print the adjusted servo reading (an angle)
        myservo1.write(pos); // Write the new angle to the servo
        delay(10); // Delay 10 milliseconds before taking another reading

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.
0
verence
verence

Best Answer 4 years ago

The magic word you are looking for is EEPROM.

It allows persisting a variable's value to survive reset and even a total loss of power.

Check here

0
iceng
iceng

Answer 4 years ago

+1

0
rojascan
rojascan

Answer 4 years ago

Thank you! That's exactly what I needed!