
If you want to completely break out of and exit a function, the simplest way is to just use the return statement. The break statement has no meaning or effect on a function.
#Arduino while loop exit code
Placing the "break" statement inside that block of code will terminate the loop, and transfer control to the next statement after the end of the loop.īut the loop() function is not a loop control statement like while and for: it is a function. They are statements that can repeatedly perform a block of code. You call while and for "loop fns" but they aren't functions.

I've read the reference and i know that "break" is used to stop the ordinary loop fns like while and for. So, what are you actually trying to accomplish by "stopping" the loop() function? But in fact it's just part of a bigger task, and there might be a better solution rather than the one you are planning.
#Arduino while loop exit how to
I'm thinking this may be a classic case of wanting to do something, and thinking you have to do something specific, and are asking how to do that one thing. Maybe there's a better way to approach it.Īnd what do you mean by stop? Do you want to break the execution of the current call, so that you can start the loop function over again from the top? Or do you really want to stop the program completely (which is what all of the suggestions so far are doing)?

Strcpy(oledMenu.mValueOrigText ,"'s start with WHY you want to stop the loop() function. demonstrate selecting between 2 options only

OledMenu.mValueHigh = oledMenu.mValueHasText - 1 #define DEBOUNCEDELAY 20 // debounce delay for button inputsĬonst int menuTimeout = 100 // menu inactivity timeout (seconds)Ĭonst bool menuLargeText = 0 // show larger text when possible (if struggling to read the small text)Ĭonst int maxmenuItems = 12 // max number of items used in any of the menus (keep as low as possible to save memory)Ĭonst int itemTrigger = 2 // rotary encoder - counts per tick (varies between encoders usually 1 or 2)Ĭonst int topLine = 18 // y position of lower area of the display (18 with two colour displays)Ĭonst byte lineSpace1 = 9 // line spacing for textsize 1 (small text)Ĭonst byte lineSpace2 = 17 // line spacing for textsize 2 (large text)Ĭonst int displayMaxLines = 5 // max lines that can be displayed in lower section of display in textsize1 (5 on larger oLeds)Ĭonst int MaxmenuTitleLength = 10 // max characters per line when using text size 2 (usually 10)Ĭonst int Time_Fast_Rotary = 350 // time fast spin encoder detectĬhar Alpha = // set parameters #define BUTTONPRESSEDSTATE 0 // rotary encoder gpio pin logic level when the button is pressed (usually 0) #define OLED_RESET 47 // Reset pin gpio (or -1 if sharing Arduino reset pin)Ĭonst int iLED = 2 // onboard indicator led gpio pin #define SCREEN_HEIGHT 64 // OLED display height, in pixels (64 for larger oLEDs) #define SCREEN_WIDTH 128 // OLED display width, in pixels (usually 128) #define OLED_ADDR 0x3C // OLED i2c address #define OLEDC 0 // oled clock pin (set to 0 for default) #define encoder0Press 40 //47 // Rotary encoder button gpio pin - 23 #define encoder0PinB 39 //34 // Rotary encoder gpio pin - 17 #define encoder0PinA 41 // 33 // Rotary encoder gpio pin - 16 Note: If you get garbage on the display and the device locking up etc. See the "menus below here" section for examples of how to use the menus Notes: text size 1 = 21 x 8 characters on the larger oLED display The sketch displays a menu on the oled and when an item is selected it sets aįlag and waits until the event is acted upon. * OLED display simple none blocking menu System - i2c version SSD1306 - 30mar22
