How can I combine 2 programs one after the other? Should I take into account the ({, }) ? I share the two programs:
Conveyor belt program:
void setup() {
pinMode(2,INPUT); //Definir pin del sensor IR
Serial.begin(9600); //Posem en marcha el monitor serie
pinMode(13,OUTPUT);//Definir pin del motor DC (aleatori)
pinMode(4,OUTPUT);//Definir pin del MOSFET
}
void loop() {
if(digitalRead(2)==1)
{
Serial.println(digitalRead(2)==1);
digitalWrite(4,HIGH);
digitalWrite(13,LOW);
}
else{
digitalWrite(13,LOW);
digitalWrite(4,LOW);
}
}
Before even starting to combine these two sketches, you have to prepare the robotic arm sketch in such away as to eliminate all the delay() statements. While is is a delay() it has no chance of executing any part of the Conveyor belt program.
I beg your pardon, my mistake, but take note of what @6v6gt says about delays and describe what the combined sketch should do
As to
Serial.println(digitalRead(2)==1);
When that line of code is executed you already know that digitalRead(2) is true so why bother reading it again ? That line of code will not be reached unless digitalRead(2) is true anyway
I didn't recognize you, but I do remember your conveyor belt!
I took a look through your other posts on this project, and it does not seem you've ever shared any kind of wiring disgram.
Also your questions and reactions indicate that you will need to know more about programming than you already do, like by a factor of 20, before doing this in the one day you have left
Hello, I am in a project that I must deliver in 4 days.
(from three days ago) would be a reasonable goal.
I suggest you file for an extension of your deadline, relax and get more familiar with some of the concepts being thrown at you here in your effort to combine multiple sketches.
I don't know why the deadline, but you aren't going to meet it. Guaranteed.
Merging two programs into a single sketch is fairly straightforward. Just remember that there can only be one setup() and one loop() function.
The problem that I see is that I have absolutely no description how your program is supposed to work when merged. Your verbose comments are no help either. (/sarcasm).
And as others have said (6v6gt), the delay statements could upset your plans. (Maybe- see my guess below). If you are expecting the belt to stop (or start- the comments aren't clear) in the presence (or absence, based on your well documented comments) of an object. It won't if the arm is in a delay(). As your well descriptive comments show, I don't know what the servo program is doing- I am being sarcastic because without comments we have no clue what you are trying to do. And in a year, neither will you.
I am just guessing, emphasis on guess since you haven't said what the project does, is that you are demonstrating an automatic conveyor. Placing the block on the belt is detected by the IR sensor to turn on the motor. What turns it off? You want to combine two sketches- which one runs first? I am guessing (again) that the arm runs first and the belt runs second. If this is a correct guess, then the delays won't hurt anything now and you just might be able to merge the programs in two days.
If you absolutely can't move your deadline at least a week, then just get another Arduino and run the two sketches independent of each other.
Let's have a look at your code. There are many people lurking for every one posting, it is possible your efforts would be instructive or meaningful to others.