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. ![]()
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...