i have recently received an assignment where i need to build a line tracking robocar that have two codes, the first one is an automatic code where the car while move on its own. The second one is a manual code in which i need to control the car manually. is there a way where i can combine these two codes in one file and switch between them, so that i can just upload one code to my arduino uno?
is there a way where i can combine these two codes in one file and switch between them,
In principle yes, but the devil will as always be in the detail.
You can in principle combine everything in the 2x setup() functions into 1x setup(), and get rid of duplicates like pinMode() on the same pins and so on.
Then put what's in loop() of 1 sketch into a function called say autoMode() and the stuff from the other loop() into manualMode().
And then in a new function called loop() call either autoMode() or manualMode() based on whatever your selection criterion is, a button press say.
But I repeat: In principle yes, but the devil will as always be in the detail.
Also posted in programming
You have the hardware on front of you.
We don't.
What have you tried?
What went wrong?
What went right?
TOPIC MERGED.
Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.