im trying to create a controller like think where a joystick if moved and the cursor moves on the lcd screen. im trying to make it so that once the if statement becomes false the for function within it will stop aswell and will only continue if the statement becomes true. so if the x_pos is not above 520 then the for function will terminate and the other statement will run.
if (x_pos > 520) {
for (byte i = 0; i < 16; i++) {
// Continue loop if x_pos > 520
lcd.setCursor(i, 1);
lcd.write(byte(0));
if (i > 0) {
lcd.setCursor(i - 1, 1);
lcd.print(" ");
}
delay(500);
}
}
}
You can’t have a delay and the for loop is in the wrong place since you don’t test the joystick anymore. Just use the loop and millis and check from time to time if the test is still true
My brother you dont understand. Im trying to create something like an xbox controller where if you move the joystick to the left the cursor goes to another spot thats what im doing. even if i swap delay for millis() it wont do nothing. my point is how to terminate a for function when the if statement it is in becomes false.
Take a piece a paper and a pencil and design a program structure based on the IPO model before start coding.
The basics for coding the project are to be found in the IDE as examples.
What you want is not very clear to me but a "For" function exits as soon as the second "header element" become false ("i < 16" in your case)
If it becomes "for (byte i = 0;i < 16 && x_pos > 520; i++)" then the loop stops (after the delay(500) expires) if x_pox <= 520.
If you want to cancel the delay as well, use millis() instead and read the three pages suggested by J-M-L Jackson
No idea what "sigma" means in this case.
My Opinion: professionals and committed, ambitious amateurs use non-blocking timing
translated into normal words
when variable x_pos has a value smaller than 520 stop printing to the lcd
whenever variable x_pos has a value greater that 520 go on printing to the lcd
is this a correct description of the funcionality you want?
without seeing where x_pos changes its value
You would have to add code inside the for-loop that does change the value of variable x_pos
If there is no code inside the for-loop that updates the value of variable x_pos how should this code ever stop before it has run through completely?
It is simply not possible! Except you are using interrupts. But if you are unexperienced with interrupts this will just mutliplicate your trouble to make it work.
As an experienced programmer I can analyse from what you have posted so far that you are more or less a beginner who has some mis-conceptions about how coding works what is possible in coding and what not.
And this is the reason why you should describe your wanted functionality in normal words by avoiding all programming terms.
This is the perfect definition of the sigma male, from that article:
Although hordes of “experts” on Reddit will claim that the sigma male is the pinnacle of masculinity, the truth is that this personality type is little more than a bitter beta.