user84737: 

I want pin 11 to give a square wave of once 3 sec

and want pin 12 to act as a switch to glow pin 13 Built in led..

connected pin 12 to GND with 10k resistor


If i fed the switch code alone it is fast(the led turn on instantly), but when i fed this code (the on in picture) it has a 1 sec lag to turn on the led. why?
And also if i connect pin 11 to 12 i assume the builtin led should turn on and off according to the wave form coming out of  but the led is always low.

user84737: Basically, the code comprises Two Parts

Square Wave with 3-sec delay on and 3-sec delay off
if the pin 12, is high pin 13 will be high and if 12 is low 13 is also low(a simple on/off switch)


The second block of code executes only after the first Block of code is done executing.
That's why when I connected the pin 11 to 12 the led wasn't shining because when the WAVE code(that first block of code which gives a square wave) was running, the second block of code was quiet hence the 12th pin was still not become a switch yet.
And the delay I told was due to this, actually, the delay is 6 sec.
Because after the switch code completes its run, it will take a whole six seconds for the Arduino to come back to switch code in the loop because the wave signal of 3 sec on and 3 sec off should run.
if you want to run two tasks at the same time you need to learn the topics of millis() and protothreading.

You can ask me why I was this dumb to ask a question like this, because the only programming language I have ever snorted is python and in there I learned python is an interpreter and it executes line by line, Since Arduino ide code is built around c++ which is the compiler.
I thought the code won't run line by line instead the code will be compiled but now only I understood that even though the file is compiled there is no chance every code can be run at the same time as the actual meaning of the compiler.

84737: <p><a href="https://i.stack.imgur.com/QhNzT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QhNzT.png" alt="This is the code" /></a></p>
<ul>
<li><p>I want pin 11 to give a square wave of once 3 sec</p>
</li>
<li><p>and want pin 12 to act as a switch to glow pin 13 Built in led..</p>
</li>
<li><p>connected pin 12 to GND with 10k resistor</p>
</li>
</ul>
<p>If i fed the switch code alone it is fast(the led turn on instantly), but when i fed this code (the on in picture) it has a 1 sec lag to turn on the led. why?</p>
<p>And also if i connect pin 11 to 12 i assume the builtin led should turn on and off according to the wave form coming out of  but the led is always low.</p>
 84737: <p>Basically, the code comprises Two Parts</p>
<ol>
<li>Square Wave with 3-sec delay on and 3-sec delay off</li>
<li>if the pin 12, is high pin 13 will be high and if 12 is low 13 is also low(a simple on/off switch)</li>
</ol>
<hr />
<p>The second block of code executes only after the first Block of code is done executing.</p>
<p>That's why when I connected the pin 11 to 12 the led wasn't shining because when the WAVE code(that first block of code which gives a square wave) was running, the second block of code was quiet hence the 12th pin was still not become a switch yet.</p>
<p>And the delay I told was due to this, actually, the delay is 6 sec.
Because after the switch code completes its run, it will take a whole six seconds for the Arduino to come back to switch code in the loop because the wave signal of 3 sec on and 3 sec off should run.</p>
<p>if you want to run two tasks at the same time you need to learn the topics of millis() and protothreading.</p>
<hr />
<p>You can ask me why I was this dumb to ask a question like this, because the only programming language I have ever snorted is python and in there I learned python is an interpreter and it executes line by line, Since Arduino ide code is built around c++ which is the compiler.</p>
<p>I thought the code won't run line by line instead the code will be compiled but now only I understood that even though the file is compiled there is no chance every code can be run at the same time as the actual meaning of the compiler.</p>
