Page 148 - KEC Khaitan C8.2 Flipbook
P. 148

Step  4   Programming in Block Coding

                            Writing the Code in Pictoblox

                               Create AI blocks for speech recognition.

                               Use servo control blocks to move facial components.
                  Linking Speech to Servo Motor Angles

                  #include <Servo.h>

                  Servo mouth, eyes, eyebrows;

                  void setup() {
                    mouth.attach(9);

                    eyes.attach(10);

                    eyebrows.attach(11);

                  }
                  void loop() {

                    String command = getSpeechCommand(); // Function to detect speech

                    if (command == "happy") {

                      moveEmoji(90, 120, 80); // Happy face movement
                    } else if (command == "sad") {

                      moveEmoji(60, 90, 40); // Sad face movement

                    } else {

                      moveEmoji(75, 100, 70); // Neutral face movement
                    }

                    delay(500);

                  }void moveEmoji(int mouthAngle, int eyeAngle, int eyebrowAngle) {

                    mouth.write(mouthAngle);
                    eyes.write(eyeAngle);

                    eyebrows.write(eyebrowAngle);

                  }
                  Final Integration and Testing

                  Combining Software and Hardware

                     Ensure that AI detects speech accurately.

                     Run the Arduino program and verify servo motor movement.




                  146   Premium Edition-VIII
   143   144   145   146   147   148   149   150   151   152   153