Hello, how many codes can I put into an arduino at the same time? I have 4 codes that I want the arduino to perform at the same time. Is that even possible to do? I’m am currently using the arduino Mega.
What do mean by "codes"?
(This doesn't seem to me to be a very showcase sort of topic. Maybe you could get a mod to move it for you?)
There is only one sketch in an arduino, but it can do several things, if you structure it properly.
several things at the same time
I am very new to programming, so sorry for the confusion. But, I mean like I want the arduino to preform different tasks at the same time. Does that make sense?
So I would need to combine them? And how would I do that?
What are these tasks? How simultaneous do they have to be?
So I am using 9 FSR and 9 LED lights and they’re are connect. If I press on the FSR the LED will turn on. So first I want the arduino to randomly select a LED light to turn on, so that’s is one code. Another code will be if the FSR is not pressed between a certain time frame that will count as a miss and if it is then it will count as a hit. Then I have a code to collect how many times that FSR is pressed and collect it into an SD card.
I want that to happen in that order. For right now that’s the only codes I will be using, but might have more later on.
So it's some sort of game involving hitting targets by the sound of it.
Arduinos are really quick compared to human reaction times, it should be trivial to make one handle all of this.
Yes it is, but how would I combine all of those codes into my schematic?
Would I just write one code after the other?
A schematic refers to hardware, code refers to software.
Your question is a little like asking how to make a fruit salad from a dictionary.
Maybe.
Have we seen your code?
I need to do more research on that, thank you for making that clear. And no I haven’t posted them
To make life easier, try to combine the separate programs one at a time and test thoroughly before trying to add another.
Also, if you're using delay anywhere, you will probably want to learn about millis instead.
Your post was MOVED to its current location as it is more suitable.
Could you also 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 in the future.
there is no easy answer to your question. it's like you asked a trig question in 2nd grade arithmetic.
before you begin you need the ability to troubleshoot and repair existing sketches, which is what you call codes. troubleshooting multiple combined sketches would be a nightmare.
find a few interesting sketches and study the similarities in structure. at the top you will find all manner of
#include "this_library"
#define thatpin 5
et cetera. to combine sketches you need to cut the defines and includes and other things from the various sketches and group them at the top.
**Major: ** insure that you do not #define the same pin as two different things. insure that no two libraries use the same reserved keywords. insure that the same variable name is not used in two sketches. this is one reason why this is beyond beginner level
then you get to void setup(). again, cut and paste and make the separate setups into one combined setup
then determine if you need to make the sketches into functions ( void dothisthing() ) and if you need to use If then or switch case or some other mechanism to invoke the various sketches
if you have questions, that means you have a ton of studying to do.
So time for you to post the four sketches.
TBH it sounds more like you are just talking about a few lines of code.
But post what you have as complete sketches that compile, run and do something that you want to be part of the combination you are trying to create.
a7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.