I want to introduce a boolean that is the first iteration of loop and then false every subsequent iteration. I want it invisible, so I have to modify loop in some way. Is that possible?

  • 2
    What do you mean by "I want it invisible"? – fuenfundachtzig Apr 7 '15 at 12:16
  • I use plclib to teach how to program the control system and I want it to be as much like real systems as possible,(no c-syntax) and when programming a sequence, it is standard with a variable with the property described in my question. Students can nothing about programming and must learn to program control systems in industry-standard I have managed to avoid c++ - syntax so far. I added a function called start() to the library, but it complicated the logic of the code in a way that is not very educational. – Erik Hellberg Apr 7 '15 at 13:54
  • So I have managed to get a number of funktions that allows one to program the arduinon without using anything other than the language elements that are similar to those found in industrial control systems, and to avoid the destrucktion of the illusion the variable need to be invisible – Erik Hellberg Apr 7 '15 at 14:13
  • So you want a variable that is limited in scope so it can only be used within your library, and is inaccessable to other (student) code? – BrettAM Apr 7 '15 at 17:29
  • So you just want to redo what you already have: setup() called once the first time, and loop() called forever afterwards? What's the point? You should edit your question to make it much clearer what you really want. – jfpoilpret Apr 7 '15 at 18:11

The way to do this isn't to overload the loop function, the way to do this is to abuse the linker and replace main().

The main.cpp file that gets used in the Arduino make prototypes main as int main(void). On my system at least the linker prefers the longer prototype, so you can just do this:

int main(int argc, char* argv[])

#if defined(USBCON)


    //The one shot loop...
    if (serialEventRun) serialEventRun();
    //Put whatever else you need to do between before the unending loop here.

    for (;;) {
        if (serialEventRun) serialEventRun();

    return 0;    

Both get compiled, but the int main(int argc, char* argv[]) prototyped version gets linked as the entry point, so your "invisibile" code gets executed.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.