In Scratch we refer to each servo as a pivot. To program the Raspberry Pi Servo Controller in Scratch, we direct what the Pivots are doing. The two words refer to the same thing but the code will only understand the pivot command.
Here are some block examples:
|
Sets the pivot on port 1 to the 0 degrees position. |
|
Sets the pivot on port 1 to 90 degrees |
|
Sets the pivot on port 1 to 180 degrees. |
You can also set the position of the pivot as a percentage value.
|
Set pivot to 0% (which means 0 degrees) |
|
Set pivot 1 to 100% (or 180 degrees) |
If you want to have the position in a variable then you would have to use a JOIN block as illustrated here:
|
Set position to 0 degrees
Repeat 4 times
Set the pivot to the specified position and wait a second.
Increment position by 45 degrees
Wait 1 second |
When using the percentage approach, we need to put the ‘%’ sign at the end so it would look like this:
If you wanted to have the pivot selection in a variable, you would need two JOIN block as follow:
|
Set player to 2 (assuming a multiplayer game)
Move the second servo to 90 degrees |