Manim Python’s Code Glow an LED using Arduino Code Explanation Line by Line

from manim import *
from manim import SurroundingRectangle as sr
from manim import ReplacementTransform as rt
class CodeFromString(Scene):
    def construct(self):
        self.camera.background_color=PURE_BLUE
        t=Text("Glow an LED using Arduino  ", font_size=45,color=RED)
        self.play(SpinInFromNothing(t),run_time=5)
        self.wait(5)
        self.play(FadeOut(t))
        mc= ("void setup()\n"\
        "{\n"\
        "pinMode(8, OUTPUT);\n"\
         "}\n"\
        "void loop()\n"\
         "{\n"\
          "digitalWrite(8, HIGH);\n"\
          "delay(2000);\n"\
          "digitalWrite(8, LOW);\n"\
          "delay(2000);\n"\
           "}\n"  )
        md=	("setup() function is used to configure Pins for INPUT, OUTPUT, signal rate etc.\n"\
        	"Block of setup() function starts here.\n"\
        	"It indicates pin no. 8 is used for OUTPUT.\n"
            "Block of setup() function ends here.\n"
            "Statements inside loop() function run forever.\n"\
            "Block of loop() function starts here.\n"\
            "digitalWrite(8, HIGH) statement will make pin no. 8 supply voltage HIGH.\n"\
             "delay(2000) will make LED glow for 2000 milliseconds.\n"
             "digitalWrite(8, LOW) statement will make pin no. 8 supply voltage LOW.\n"\
             "delay(2000) will make LED off for 2000 milliseconds.\n"\
             "End of loop() function\n")
        
        mrc= Code(code=mc, tab_width=4,style=Code.styles_list[10],language="C",font_size=15,line_spacing=2,font="georgia")
        mdesc= Code(code=md, tab_width=4,style=Code.styles_list[10],language="C",font_size=15,line_spacing=2,font="georgia")
        self.add(mrc[0])
        self.add(mrc[1])
        self.add(mdesc[0])
        self.add(mdesc[1])
        mdesc.move_to(1.50*RIGHT+0.25*UP)
        mrc.move_to(5.00*LEFT+0.25*UP)
        ################
        self.wait(5)
        self.add(mrc[2][0])
        self.play(Circumscribe(mrc[2][0],buff=0.01,time_width=5),run_time=5)
        self.wait(5)
        self.add(mdesc[2][0])
        ar1=[Arrow(mrc[2][0],mdesc[1][0],color=RED,)]
        self.play(GrowArrow(ar1[0]))
        self.play(Circumscribe(mdesc[2][0],buff=0.01,time_width=5))
        self.remove(*ar1)
        self.wait(5)
        #######################################
        self.add(mrc[2][1])
        self.play(Circumscribe(mrc[2][1],buff=0.01,time_width=5))
        self.wait(5)
        self.add(mdesc[2][1])
        ar2=[Arrow(mrc[2][1],mdesc[1][1],color=RED,)]
        self.play(GrowArrow(ar2[0]))
        self.play(Circumscribe(mdesc[2][1],buff=0.01,time_width=5),run_time=5)
        self.remove(*ar2)
        self.wait(5)
        #######################################
        self.add(mrc[2][2])
        self.play(Circumscribe(mrc[2][2],buff=0.01,time_width=5),run_time=5)
        self.wait(5)
        self.add(mdesc[2][2])
        ar3=[Arrow(mrc[2][2],mdesc[1][2],color=RED)]
        self.play(GrowArrow(ar3[0]))
        self.play(Circumscribe(mdesc[2][2],buff=0.01,time_width=5),run_time=5)
        self.remove(*ar3)
        self.wait(5)
        #######################################
        
        #######################################
        self.add(mrc[2][3])
        self.play(Create(mrc[2][3]),Circumscribe(mrc[2][3],buff=0.01,time_width=5),run_time=5)
        self.wait(5)
        self.add(mdesc[2][3])
        ar4=[Arrow(mrc[2][3],mdesc[1][3],color=RED)]
        self.play(GrowArrow(ar4[0]))
        self.play(Circumscribe(mdesc[2][3],buff=0.01,time_width=5),run_time=5)
        self.wait(5)
        self.remove(*ar4)
        #######################################
        self.add(mrc[2][4])
        self.play(Circumscribe(mrc[2][4],buff=0.01,time_width=5),run_time=5)
        self.wait(5)
        self.add(mdesc[2][4])
        ar5=[Arrow(mrc[2][4],mdesc[1][4],color=RED)]
        self.play(GrowArrow(ar5[0]))
        self.play(Circumscribe(mdesc[2][4],buff=0.01,time_width=5),run_time=5)
        self.wait(5)
        self.remove(*ar5)
        self.wait(2)
        #######################################
        self.add(mrc[2][5])
        self.play(Circumscribe(mrc[2][5],buff=0.01,time_width=15),run_time=5)
        self.wait(5)
        self.add(mdesc[2][5])
        ar6=[Arrow(mrc[2][5],mdesc[1][5],color=RED)]
        self.play(GrowArrow(ar6[0]))
        self.play(Circumscribe(mdesc[2][5],buff=0.01,time_width=15),run_time=5)
        self.wait(5)
        self.remove(*ar6)
        self.wait(5)
        #####################################
        self.add(mrc[2][6])
        self.play(Circumscribe(mrc[2][6],buff=0.01,time_width=15),run_time=5)
        self.wait(5)
        self.add(mdesc[2][6])
        ar7=[Arrow(mrc[2][6],mdesc[1][6],color=RED)]
        self.play(GrowArrow(ar7[0]))
        self.play(Circumscribe(mdesc[2][5],buff=0.01,time_width=15),run_time=5)
        self.wait(5)
        self.remove(*ar7)
        self.wait(5)
        #####################################
        self.add(mrc[2][7])
        self.play(Circumscribe(mrc[2][7],buff=0.01,time_width=15),run_time=5)
        self.wait(5)
        self.add(mdesc[2][7])
        ar8=[Arrow(mrc[2][7],mdesc[1][7],color=RED)]
        self.play(GrowArrow(ar8[0]))
        self.play(Circumscribe(mdesc[2][7],buff=0.01,time_width=15),run_time=5)
        self.wait(5)
        self.remove(*ar8)
        self.wait(5)
        #####################################
        self.add(mrc[2][8])
        self.play(Circumscribe(mrc[2][8],buff=0.01,time_width=15),run_time=5)
        self.wait(5)
        self.add(mdesc[2][8])
        ar9=[Arrow(mrc[2][8],mdesc[1][8],color=RED)]
        self.play(GrowArrow(ar9[0]))
        self.play(Circumscribe(mdesc[2][8],buff=0.01,time_width=15),run_time=5)
        self.wait(5)
        self.remove(*ar9)
        self.wait(5)
        #####################################
        self.add(mrc[2][9])
        self.play(Circumscribe(mrc[2][9],buff=0.01,time_width=15),run_time=5)
        self.wait(5)
        self.add(mdesc[2][9])
        ar10=[Arrow(mrc[2][9],mdesc[1][9],color=RED)]
        self.play(GrowArrow(ar10[0]))
        self.play(Circumscribe(mdesc[2][9],buff=0.01,time_width=15),run_time=5)
        self.wait(5)
        self.remove(*ar10)
        self.wait(5)
        #####################################
        self.add(mrc[2][10])
        self.play(Circumscribe(mrc[2][10],buff=0.01,time_width=15),run_time=5)
        self.wait(5)
        self.add(mdesc[2][10])
        ar11=[Arrow(mrc[2][10],mdesc[1][10],color=RED)]
        self.play(GrowArrow(ar11[0]))
        self.play(Circumscribe(mdesc[2][10],buff=0.01,time_width=15),run_time=5)
        self.wait(5)
        self.remove(*ar11)
        self.wait(5)
        #####################################
        self.play(FadeOut(mdesc))
        newon= ImageMobject("newon.png").scale(0.80)
        newoff= ImageMobject("newoff.png").scale(0.70)
        newon.width =1.0
        newon.height =4.0
        newoff.width =1.0
        newoff.height =4.0
        for i in range(10):   
               self.play(Write(mrc[2][6]),Circumscribe(mrc[2][6],buff=0.01,time_width=1),run_time=1)
               newon.move_to(2.50*RIGHT+0.30*UP)
               self.add(newon)
               self.play(Write(mrc[2][7]),Circumscribe(mrc[2][7],buff=0.01,time_width=1),run_time=1)
               self.wait(2)
               self.play(Write(mrc[2][8]),Circumscribe(mrc[2][8],buff=0.01,time_width=1),run_time=1)          
               newoff.move_to(2.50*RIGHT+0.30*UP)
               self.add(newoff)
               self.play(Write(mrc[2][9]),Circumscribe(mrc[2][9],buff=0.01,time_width=1),run_time=1)
               #self.remove(*off)
               self.wait(2)
        #######################################
        self.play(FadeOut(mrc))
        self.play(FadeOut(newon))
        self.play(FadeOut(newoff))
        t=Text("Thanks for  Watching ", font_size=45,color=RED)
        self.play(SpinInFromNothing(t),run_time=5)
        self.wait(2)
        #######################################


'''void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
}'''

See the output video of the above code

©Postnetwork-All rights reserved.