In Arduino the sketch.ino
is the main (and only) program, which runs on the processor.
If you upload another sketch to HW, then the previous one is overwritten and does not longer exist on the HW. So there is no way, they can share variables, as they never are run at the same time.
(You can store some values to EEPROM or to external devices, but it is other thing).
What you probabely want to do is use the second file as a library
, which is collection of variables and functions, that more then one program can use. Anyway what is used is the text of the library, not the values assigned to variables in one sketch.ino
- so other sketch.ino
using the same library would have the functions and variables of the same name accessible, but as it is compiled to othe program, the values assigned in one sketch would not be visible in other sketch.
Can you specify, why you want to use variables and functions accross multiple .ino files?
If it is just to not have type it again and again and fix found bugs in each aned every copy separately, then you are looking for libraries
.
If you want to share also values (like read and compute value in one .ino then upload another .ino and use the result) you are looking for persistent storages
(EEPROM on the chip, SD card via some reader or something like that.
If you want have more Arduinos running at the same time and sharing some values, you are looking for networks
, like I2C, Serial communication, Ethernet and such.
If you want run mor programs on one arduino at the same time, you are looking for multitasking
where each program is interrupted repeatedly and other one is continued, fast enought to user not notice, or for creatinig more functions and call them from loop() one after one to eg. read sensors, then light LEDs then run motors. State automats
can make your way here easier.
WHY?
(why you want two sketch files and why share variables between them) as maybe you are trying to emulate something, which is already present and in much better and more usable form.