Have you ever seen a lucky cat waving her arm at the counter of a roadside shop? In this lesson, we will use a very interesting device, servo to assemble a lucky cat.
In this lesson, we just need a Servo to help assemble a lucky cat. Connect the yellow wire of servo to P0, the red wire to 3V3 and another wire to GND.
Click Create variable button to create a variable, servo.
Assign the value of pin P0 to the variable servo, which is used in place of P0 in the following codes.
Drag a count with i from 1 to 10 by 1 block from the Loops category to the Forever block.
Then change the parameter to count with I from -45 to 45 by 10. This step means that the variable i ranges from minus 45 to plus 45 at the rate of 10.
Under the Raspberry Pi category, we can find the servo set P0 angle 0 block then put it into do block. Next, put the servo block from the Variables category into P0; variable i to number 0 as shown below. Then the delay value is set to 3 ms.
After the lucky cat’s arm turns from -45 to 45 degrees, let it stay at 45 degrees for 800ms (0.8s).
In the same way, we should put the lucky cat’s arm back to -45 degrees for 800 ms.
Save the project and flash it into the Raspberry Pi (refer to lesson 0 for details). When the code is uploaded successfully, you will see the repetitive swing of lucky cat’s arm.
Take out the matching cardboard of this lesson.
To achieve the desired effect, the arm of the lucky cat should be attached on the servo with double-sided tape.
Stick the servo on the back of the cat.
Fold the bracket of the lucky cat according to the creases on the cardboard. Then stick it to the back of servo.
In this lesson, only one servo is used. In operation, you can directly mount the servo on the Raspberry Pi board.