2017-01-05 19:00:36 +01:00
|
|
|
# Code
|
2017-09-07 22:42:08 +02:00
|
|
|
## @description code to make the inchworm alive
|
2017-01-05 19:00:36 +01:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~avatar avatar
|
2017-01-05 19:00:36 +01:00
|
|
|
|
|
|
|
Add code to make the inchworm move.
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~
|
2017-01-05 19:00:36 +01:00
|
|
|
|
2017-01-05 22:28:06 +01:00
|
|
|
## Duration: ~30 minutes
|
2017-01-05 19:00:36 +01:00
|
|
|
|
2017-01-05 22:30:14 +01:00
|
|
|
## Step 1: walk forever
|
2017-01-05 19:00:36 +01:00
|
|
|
|
|
|
|
In order for the inchworm to move, the @boardname@ needs to command the servo to go between ``0`` and ``180`` degrees
|
|
|
|
at a certain pace. In the code below, the user pressed button ``A`` to launch the inchworm.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
input.onButtonPressed(Button.A, () => {
|
2017-01-06 16:19:00 +01:00
|
|
|
pins.servoWritePin(AnalogPin.P0, 0);
|
|
|
|
basic.pause(500);
|
|
|
|
pins.servoWritePin(AnalogPin.P0, 180);
|
|
|
|
basic.pause(500);
|
2017-01-05 19:00:36 +01:00
|
|
|
});
|
2017-01-05 22:28:06 +01:00
|
|
|
```
|
2017-01-05 19:00:36 +01:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~ hint
|
2017-01-05 19:00:36 +01:00
|
|
|
|
|
|
|
You may have noticed that the inchworm can be rather slow or simply won't move. Try to improve the design of your legs, teeth
|
|
|
|
so that the inchworm goes as fast as possible. Trying it on carpet also great helps avoiding skidding.
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~
|
2017-01-05 19:00:36 +01:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~button /projects/inchworm/connect
|
2017-01-31 17:29:25 +01:00
|
|
|
NEXT: Connect
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~
|