Hi guys. Can I store multiple programs on the Arduino using diffeerent pins for different programs?
You can store only one sketch. You can define multiple functions in that one sketch. Choose which function is executed by the state(s) of pins. Look up state machine programming.
If you need to ask this question, it is likely that you will not understand my answer.
The short answer is: No.
The longer answer is: It would be possible to combine the programs, and then write a "super" program that chooses what to do based on the inputs ("diffeerent pins"). Of course, the size of the overall program must be smaller than the memory size of the Arduino that you are using. And, of course, the programs must not make use of the pins that you use for the choice.
If you need to ask this question, you probably do not know how to combine the programs. Sorry, but statistically that is the way that it works out. ![]()
Have a look at how the code is organized into functions in planning and implenting a program. You could think of the different functions as different programs running under central control of the loop() function.
...R
SagarDev:
Hi guys. Can I store multiple programs on the Arduino using diffeerent pins for different programs?
It would be easier to give a definitive answer if you explained exactly what you want to do. For instance, would only one "program" run at a time or do you need to run several "programs" at the same time ?
And you could use the fact that each digital pin has two states to use a binary counter type of thing to select the "program" (or more correctly the function as Robin2 points out).
So in very pseudo code and assuming you allocate 2 pins to the decision you have 4 possibilities:
if pin1 low and pin2 low //0
perform functionA
if pin1 low and pin2 high //1
perform functionB
if pin1 high and pin2 low //2
perform functionC
if pin1 high and pin2 high //3
perform functionD
You could use analog pins as well, provided you could rely on the thresholds being consistent over time.
SagarDev:
Hi guys. Can I store multiple programs on the Arduino using diffeerent pins for different programs?
An Arduino is just a microcontroller without any operating system.
An Arduino is NOT a computer with a full featured operating system.
So you just can have ONE program on an Arduino at the same time.
What you can do is a single all-in-one program that contains all functions you will ever need.
And in the "setup()" function you could include a "program selection".
For example wait until a certain button is pressed.
Or wait until a button is pressed a certain number of times.
Or wait until something had been sent over the "Serial Monitor" to the Arduino.
And after the "program selection" has been made, you start the code that had been selected.
. . . and remember that your individual functions may have to be a bit clever managing the memory they use.
Thanks for All Guys