Page 39 - Toucpad robotics C11
P. 39

Structure of an Algorithm
                 Most algorithms follow a similar logical structure:

                                 Step                                       Explanation
                       Input                    Gather data from sensors or external sources.

                       Processing               Apply logic, calculations, or conditions.
                       Decision-making          Use comparisons or conditional statements to determine the next step.
                       Output/Action            Send signals to actuators (motors, LEDs, arms, etc.) or display the result.
                       End/Repeat               Stop or repeat the loop as needed.
                 Example: Temperature-Controlled Fan
                 1.  Start
                 2.  Read temperature from the DHT11 sensor
                 3.  If temperature > 30°C   Switch on fan

                 4.  If temperature ≤ 30°C   Switch off fan
                 5.  Repeat
                 6.  End
                 This simple example demonstrates how input (temperature) leads to logical decision-making and output (fan on/off).

                 Flowchart: The Visual Form of an Algorithm
                 An algorithm can be represented textually or visually. The visual representation is called a Flowchart.

                 A flowchart uses specific symbols to represent different types of instructions or decisions, helping students visualize the
                 logic easily.

                     Symbol           Purpose       Example                              Start
                  Oval            Start or End      Start / Stop

                  Parallelogram   Input or Output   Read sensor value
                  Rectangle       Process or Action  Move forward
                                                                                         Read
                  Diamond         Decision          Is obstacle detected?               A, B, C
                                                    Indicates direction of
                  Arrow           Flow of control
                                                    sequence
                                                                                 No               Yes
                                                                                          Is
                                                                                         A > B



                                                                      Yes             No     No              Yes
                                                                             Is                        Is
                                                                            B > C                    A > C





                                                               Print "B is the        Print "C is the       Print "A is the
                                                              largest number"       largest number"        largest number"






                                                                                         Stop

                                                                                                                       37
                                                                                    Introduction to Robots: What Exactly are They?
   34   35   36   37   38   39   40   41   42   43   44