Go Down

Topic: glcd menu help (Read 345 times) previous topic - next topic

haha54321

Hello I am a beginner trying to figure out a way to make a 'blocking' menu to go to a loop.

This doesn't work. It gives: error: label 'loop' used but not defined

void menu(){

GLCD.print("start");
val=digitalRead(button1);

if (val==HIGH){ goto loop;}}

void loop() {  code
}


billroy

I believe what you want is a function call:
Code: [Select]

void menu() {
  GLCD.print("start");
  val=digitalRead(button1);
  if (val==HIGH) doSomething();
}

void loop() { 
   …code...
}

void doSomething() {
  …code…
}


-br

haha54321

Thanks. So I tried this with the accelstepper library (everything was defined earlier in the code):

So when I press the button2, the program breaks the menu and goes to the loop, running the stepper motor properly. However, when I go to the doSomething, the stepper motor does not work...I am sure I have defined everything correctly, but somehow the doSomething doesn't run the motor.

Code: [Select]
void menu() {
int ter=2;
while (ter==2){
  GLCD.print("start");
  but1=digitalRead(button1);
  but2=digitalRead(button2);
  if (but1==HIGH) doSomething();
if (but2==HIGH) {ter=0;GLCD.ClearScreen(); break;}
}
}

void loop() { 
...code...
for(int l=0; l<GLCD.Width; l++){
...code ...
int val=digitalRead(input1)
if (val<90){
stepper.setSpeed(80);
              stepper.runSpeed();}
              else if (val<70)
              {stepper.setSpeed(80);
              stepper.runSpeed();}
              else
              {stepper.setSpeed(50);
              stepper.runSpeed();}

}
}


void doSomething() {
 
int tt=3;
while (tt==3){
GLCD.ClearScreen();

GLCD.CursorToXY(50,5);
GLCD.print("Reverse");
stepper.setSpeed(50);
              stepper.runSpeed();}

}

HazardsMind

Could you please post the full code, and use better variable names.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

haha54321

I was able to figure out the problem. Thanks anyways!

Go Up