Startup keeps running

This is some code from a bigger project. This is startup code that is supposed to run only once. Howeve, it keeps resetting stuff. So I added the two lines that have the global variable ‘run’ . Now it performs as it should. It’s not a problem for me, but it isn’t what the documentation describes. Without the ‘run’ lines if I comment out the ‘draw’ sub it performs properly, otherwise it’s a mess.

void setup ()
{  fullScreen();
   rectMode(CENTER);
   background(hideColor);
   println("set_up");
   int i;
   if (run == 0)  //This code runs only once
   {  for (i = 0; i < 5; i++)  //set all IO data to 0
     {  roIN[i] = 0;
     };
     for (i = 0; i < 10; i++)
     {  roOUT[i] = 0;
     };
     for (i = 0; i < 3; i++)
     {  ccIN[i] = 0;
     };
     for (i = 0; i < 4; i++)
     {  ccOUT[i] = 0;
     };
     for (i = 0; i < 6; i++)
     {  wsIN[i] = 0;
     };
     for (i = 0; i < 11; i++)
     {  wsOUT[i] = 0;
     };
     for (i = 0; i < 3; i++)
     {  acIN[i] = 0;
     };
     for (i = 0; i < 3; i++)
     {  acOUT[i] = 0;
     };
     for (i = 18; i < 99; i++)      // draw all blocks
     {  drawBlock (i);
     }
     line (865,  76,  888,  59);    //draw al dark territory
     line (888,  59,  942,  59);  
     line (1354, 204, 1377, 222);
     line (1401, 222, 1629, 222);
     line (1676, 222, 1812, 222);
     drawSwitch (0,  1377, 222,  1,  1, black);
     drawSwitch (0,  1653, 222, -1,  1, black);
     line (1401, 239, 1432, 263);
     line (1455, 263, 1575, 263);
     line (1598, 263, 1621, 245);
     drawSwitch (0, 1432, 263,  1,  1, black);
     drawSwitch (0, 1598, 263, -1,  1, black);
     line (1432, 303, 1598, 303);
     line (1455, 280, 1486, 303); 
     line (1543, 303, 1574, 280);
     line (1248, 352, 1271, 370);
     line (1148, 352, 1248, 352);
     line (1487, 459, 1507, 474);
     line (1507, 474, 1570, 474);
     line (728, 835,  755, 818);
     line (755, 818,  819, 818);
     line (345, 940,  403, 940);
     line (403, 940,  426, 923);
     line (1087, 795,  1110, 777);
     line (1110, 777,  1175, 777);
     
     for (i = 0; i < 131; i++)
     {  drawButton(i);
        drawSignal(i);
     }
     run++;
   };
}

void draw()
{  
}

I don’t know why setup() runs multiple times, it shouldn’t. I suspect it relates to the empty draw() function. You shouldn’t use empty draw(), I suspect it is run 60 times a second even if it’s empty. Perhaps empty draw() triggers rerun of setup().

That appears to be correct. WhenI put some empty subs in draw it ran only once. Not a big deal- I have much bigger problems to take care of.