![]() ![]() If we leave it unfed, it will become hungry and when it is starved, it will shut down finally. The pet dog needs our attention all the time. The first one is used to calculate the hungry time and boring time. We have created two parallel code segments. The following code segments include the main controlling logic. At the end of the running procedure, both motors return to the position 0, so the pet dog resumes its initial “sitting” position. The effect is that one leg moves forward while the other leg moves backward. The program repeats 5 times and within each iteration, the two motors in the motor pair run at opposite speed, that is to say, left motor runs at -50 speed, while right motor runs at 50 speed, and vice versa. We define a block called “running”, whose code is similar to the tapping block. The pet dog will run when the ultrasonic sensor identifies any object closer than 8 cm. After swaying the legs, the program sets both motors to the position of 0, so the pet dog resumes its initial “sitting” position. When we set negative motor speed, both legs will move backward. When we use motor pair and set positive motor speed, both legs will move forward. Pay attention that if you swap the position of Port D and Port A to use “set movement motors to A+D”, the final effect will be different since the program takes Port A as the left motor. Recall that the left leg is connected to Port D and right leg is connected to Port A, therefore, the motor pair should use “set movement motors to D+A”. In the block “tapping”, the program uses motor pair so that both legs could move at the same time. The pet dog has response to user’s action. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
May 2023
Categories |