Introduction
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.
Components
Circuit
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.
Programming Steps
Step 1
Click Create variable button to create a variable, servo.
Step 2
Assign the value of pin P0 to the variable servo, which is used in place of P0 in the following codes.
Step 3
Drag a count with i from 1 to 10 by 1 block from the Loops category to the Forever block.
Step 4
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.
Step 5
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.
Step 6
After the lucky cat’s arm turns from -45 to 45 degrees, let it stay at 45 degrees for 800ms (0.8s).
Step 7
In the same way, we should put the lucky cat’s arm back to -45 degrees for 800 ms.
Step 8
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.
Fold Cardboard
Step 1
Take out the matching cardboard of this lesson.
Step 2
To achieve the desired effect, the arm of the lucky cat should be attached on the servo with double-sided tape.
Step 3
Stick the servo on the back of the cat.
Step 4
Fold the bracket of the lucky cat according to the creases on the cardboard. Then stick it to the back of servo.
Step 5
In this lesson, only one servo is used. In operation, you can directly mount the servo on the Raspberry Pi board.