Loop iteration and more tractor troubes

This might be easy but i cant seem to find a fix... for now i am using a made up array, in the near future i want to adjust that so that the arduino can recieve a string(or better an array) and read that continually updated string. for now i have made this one. Along with the confusion, i have to wonder what the best way to handle this device would be. i am working on a device that is pulled by a tractor. it has a camera, computer, arduino, encoder and solenoid valves lined up in that order. the camera will take picture of the ground below it to identify weeds in a crop inorder to tell the arduino to activate the solenoids at gien points. the arduino will read these points, know when to fire off a solenoid, and wait for the encoder to hit the right step before firing. i want each if statement to control a solenoid valve that will spray when activated. the issue is that i will be recieving a matrix every foot or so containing ones and zeros where '1' signifies spray and '0' do nothing. the spray nozzle is to be activated by an encoder inorder to track distance traveled rather than moment to spray. my plan was to recive a string, convert it into an array, read the array, and mark certain values the encoder will read at which point it will acivate the soleoid(im using LEDs for the first practice runs). the more i think about it, it might be best to read the array one row at a time, though im not certain. all advice is appreciated. :slight_smile:

so,, my side question would belong in the feasability department but would this be the best way to do it? or should i split the array and have each nozzle recieve independent arrays which it must read inorder to mark the encoder for partcular stepps at which it must spray? im not sure how to best split these commands andwether or not commands such as 'delay' can be activated for individual pins.

and i was curious, if anyone knew how and where memory for the command to fire off the solenoids is held even after im further down the loop. so like if the encoder is at step 755 when i recieve my new array, and i have to spray solenoid 1 at 769, but then again at 789, where would this command be held because the arduio will read through the entire array much faster than i can fire off the solenoid

void setup() {
  
Serial.begin(9600);
}

void loop() {
  
int i=0;
int allie[]={1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1};
for(int i=0; i < 4; i++){

   if (allie[i] == 1){
   Serial.println("on");
   delay(1000);}

   if (allie[i+1] == 1){
   Serial.println("2on");
   delay(1000);}

   if (allie[i+2] == 1){
   Serial.println("3on");
   delay(1000);}

   if (allie[i+3] == 1){
   Serial.println("4on");
   delay(1000);}

}
}

ps know this is basic but im really new to this and my intership did not give me any books, help, or professional advice by which i could work... they said to figure it out but im a mehanical engineer, so im learning as i create. I may move most of this question back to the project guidance but i figure technical advice will help me just as much in solving the current problem as deciding how to cange it. Thanks!

EDIT: PaulS, removing it didn't change anything and because i didn't think it was a huge deal...

for(int i=0; i < 4; i++);{

WTF is that ; there for?

Why the hell can't you indent properly?

my intership did not give me any books, help, or professional advice by which i could work... they said to figure it out but im a mehanical engineer, so im learning as i create

Is google broken in your country ?

because i didn't think it was a huge deal...

In computer programming, syntax matters. What you write, is what you get. If you write nonsense, you get nonsense.

It's not like mechanical engineering, where if your piece of steel needs 10 kN to bend, and you are only loading it with 2 kN, then you know it is OK. And if your estimate of a 2 kN load is 50% wrong, You'll still be OK.

If you randomly put semicolons in the wrong place, you won't be ok.

Save yourself some time and find a good elementary textbook or online tutorial for C/C++ .

the more i think about it, it might be best to read the array one row at a time

I agree. One row at a time should work better.

pamoreno:
EDIT: PaulS, removing it didn't change anything and because i didn't think it was a huge deal...

In this case that Paul has quoted it is actually a huge deal. It did change a lot, and the fact it's still not working simply indicates there are more errors, possibly not just in syntax but in your implementation.
Did you do a first year course in programming for your degree? Java, Matlab, C ??

As you're probably aware from the wrath, putting the semicolon after your for loop is a big deal, a very big deal, but in case you didnt know why:

for( int i=0; i<4; i++ )
{
  // This code in here is called 4 times! and i gives us the current loop counter!
}

for( int i=0; i<4; i++ );
{
  // This code in here is called ONCE! Further more, the use of i will likely give syntax errors
}

Also you have an array of 16 ones and zeroes, and your for loop is constantly cycling the first 4.