hi i am new to both coding and arduinon. i am trying to make a stepper motor run in different directions using 2 photogates. in the beginning the motor keeps running and when i block one photogate the direction of rotation must change. when i use the break function it can be seen in the code below i keep getting an error saying "break statement not within loop or switch". can i get some help here please?
You can only 'break;' out of a for/while/do-while statement or switch-case. You can exit from a function with 'return;' but loop() will just get called again. If you want loop() to stop executing you can use an infinite loop:
while(true) /* Do Nothing */ ;
Your sketch will do nothing further until you reset the processor.
dd2509:
when i use the break function it can be seen in the code below i keep getting an error saying "break statement not within loop or switch". can i get some help here please?
Compiler has already told you, your use of 'break' is invalid.
To help you with your code you have to tell us what you expected from 'break'?
And I think it is a bad idea to use pin 1 as output. Pin 0 and pin 1 is used for serial communication and you do use serial communication in your code so it will interfere.
@dd2509, you need to tell us in English (not code) how you expect your program to work. I don't understand the logic of what you think might be happening.
For example if this was valid
if(v1<v2)
{
[b]break[/b];
sensor();
how could the lines after break ever be implemented?
In general you never try to stop the program. You just get it to stop doing what you don't want it to do.