Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 114 - 2629_Devagiri_C-7
P. 114

    Step  8    Click the Code button to open the code editor.

                       Step  9     Click on the EDIT MODE dropdown button and
                                  select the Blocks option.
                       Step  10    Click  on the  Create  variable button in  the
                                  Variables section and name it Nightsensor.

                       Step  11    Drag  and place the  set Nightsensor  to
                                  block  from the  Variables section  into  the
                                  editor window.

                       Step  12    Drag and place the read digital pin block from
                                  the Input section inside the ‘set Nightsensor to’ block and set it to pin 7.
                       Step  13    Drag and place the print to serial monitor block from the Output section and set
                                  Nightsensor inside it to print the sensor’s value to the serial monitor.

                       Step  14    Drag and place the if then else block from the Control section. Place the comparison
                                  block from the Math section and set it to =. Compare Nightsensor with 0.

                       Step  15    Inside the if block, drag and place the set pin 8 to HIGH block from the Output section
                                  to turn pin 8 on if Nightsensor equals 0.
                       Step  16    Inside the else block, drag and place the set pin 8 to LOW block from the Output
                                  section to turn pin 8 off if Nightsensor does not equal 0.

                       Step  17    Click on the Start Simulation button to see the Smart Lamp turn ON or OFF based on
                                  the Nightsensor’s value.
                      Text based programming:

                       Step  18    Click on the EDIT MODE dropdown button and select the Text option. The code you
                                  created will be displayed here.

                                                                                                        QR QUEST

                                                                                                    Visit the given link
                                                                                          to learn how to create an RGB
                                                                                                   LED circuit:
                                                                                              https://www.youtube.com/
                                                                                              watch?v=YqHkULDmmGU
                                                                                         Answer the given questions:
                                                                                         1.   Write  the  key  components
                                                                                           needed to design an RGB LED
                                                                                           circuit.
                                                                                         2.   What  role does  the  resistor
                                                                                            play in the LED circuit?

                      Here’s an explanation of the code you created:

                          int Nightsensor = 0: This line declares a variable named Nightsensor to store the state of the
                         light sensor. It is initially set to 0.

                       112
                            Premium Edition-VII

| 109 110 111 112 113 114 115 116 117 118 119 |