Can I rename variables?

Can I rename variables?

My balancing robot project is in the MakeBlock firmware. It uses PID. I would like to convert to the Arduino PID library. The problem is that both are using to same variable names. Namely, PID, P, I, D, Setpoint and so forth. So, just including the library creates 100 errors. I would like to have the option of figuring out the library while leaving the original code in place.

**Is this possible? **
Is there a method to do this?

I use Notepad++ to edit text files on Windows, works great for .ino files.

Use the "replace all" option, very carefully.

The Arduino IDE also has an Edit>Find>replace(all) option.
Leo…

Variable names in a library do not normally affect variable names in your sketch.

In one of my projects I'm including a number of libraries all of which have a few variables with the same name, and use the same name in my main sketch as well. No issues. After all, it's a different name space.

CLplaneguy:
My balancing robot project is in the MakeBlock firmware. It uses PID. I would like to convert to the Arduino PID library.

Would that be a good idea ?

...R

A well-written library should appear to the code like every other library. If I change from an LCD screen to an OLED screen then I would only expect to change a few little things like maybe the .begin() is different. Printing text to the screen will use the .print() method which appears to be the same even though it is totally different technology underneath.

If you are changing from a "homemade" system to put a library in its place then you have to rip out all that old code. You can't keep both.

Reaming the variables in a library just so you can use them in you own sketch seems completly peverse to me.

If the Library uses 'PID' for instance and it causes a conflict with a sketch, I would chnage the sketch variable to something like 'My_PID'.

jremington:
Use the "replace all" option, very carefully.

You do have to be very careful using any type of automated replacement. If a variable name is also part of another variable name, or part of a c++ command, then you can end up with some unintended changes. If you have the editor set to replace whole words only, it may not work properly with the syntax of a programming language. The editor also needs to be able to handle case sensitivity, because its possible to have two variable names that vary only in whether a letter is upper or lower case.