The Crazy Pirate Ship is the fair ride from Level 1, Lesson 7. But this one can go all the way over the top. A tyre in the middle drives the ship. There are two Touch Sensors, one left and one right. A person uses them to push it either way.
You cannot get it round with one long push. The motor is not strong enough. You get it round by pushing the right way at the right moment. You do it again and again, until each swing is bigger than the last.
So a person has to be at the buttons, watching. One stack of blocks, running top to bottom, can only wait for one button at a time. The Lift in the last lesson had this problem.
In the real world 5 min
Where you have seen it
Almost every big theme park in the world has a swinging ship. The gentle ones swing to about forty-five degrees. The scary ones go past straight up. They hang you upside down at the top.
A swinging ship ride on its tall frame, at Leofoo Village Theme Park. Photo: milst1 / Wikimedia Commons (CC BY-SA 2.0).
Why it is built that way
The ride does not have a huge motor. It has a small one. It also has a driving wheel that presses on the bottom of the ship. It is just like the tyre in your model. It uses the same trick you met with the Clock Ticking in Level 1, Lesson 13.
Each push is small. But push while the ship is already moving that way, and it adds to the swing. A few dozen pushes build up to a huge swing. That build-up is called momentum. It is stored in the swing, not in any part of the machine.
What would go wrong without it
Push at the wrong moment, and you do not just waste the push. You take some swing away. Push a ship that is coming towards you, and it slows down.
So the person running the ride must watch the ship all the time. They push it one way, then the other. A machine that can only do one thing at a time is no use to them.
A machine a person drives must listen all the time. It cannot just work down a list.
Before you build 1 min
This model has no step-by-step build guide. The video below is not one. It is a film of a finished Crazy Pirate Ship going over the top. Watch it to see what you are aiming for. Watch what the tyre does when the ship changes direction. Then build from your teacher’s model. You are not missing a page. There is no page.
The main concept — more than one stack 6 min
A program does not have to be one stack of blocks. You can put down a few separate stacks, each with its own hat. The Brick runs them all at the same time.
Most of your programs start with one hat: when program starts. There are other hats. You used some on the Crane in Lesson 25. They wait for other things.
Hat block
Its stack runs when…
when program starts :: events hat
the green flag is pressed. Once.
[1 v] when [pressed v] :: events hat
the Touch Sensor in port 1 is pressed. Every time, for as long as the program runs.
when [center v] button [pressed v] :: events hat
a button on the Brick itself is pressed.
A sensor hat is not the same as wait until. The difference is the whole lesson. Wait until stops the program in one place until one thing happens, once. A hat waits the whole time. It runs its stack every single time.
the program starts — all of these begin here
stack 1 · Medium Motor
when program starts
A start motor clockwise
stack 2 · status light
when program starts
forever
set status light to green
wait 0.5 seconds
set status light to red
wait 0.5 seconds
stack 3 · drive base
when program starts
start moving straight: 0
One stack, one jobAll three at once
Three stacks, each with its own hat block. All three start the moment the program starts — none of them waits for the others.All three are running in the same instant: the Medium Motor is turning, the light is flashing, and the drive base is rolling.Each stack owns one thing and never touches another stack's job. That is the rule that makes this work.Finished. All three jobs ran the whole time, and none got in another's way.
three stacks, three jobs
Every stack is highlighted at the same moment on purpose — that is what running in parallel looks like. The switch above changes only what the third stack controls.
Look at how the demo is drawn. The stacks are side by side under one start bar. They are not one on top of the other. Nothing in one stack comes “before” anything in another. They are all running.
One stack for each thing that can happen. That is how a program listens to two buttons at once. It never has to ask “which one?”
There is one rule: one boss per motor. Say two stacks both try to drive port A at the same moment. The last one wins, and the motor goes wrong. Today that is safe, because a person only presses one button at a time. But watch out when you add a third stack.
▶Two things at once, and the Touch SensorAll about stacks that run together, and the buttons this model uses. Open one if you are not sure yet.Show meHide
ComponentControl5 min
Two things at once
A program does not have to be one long column of blocks. Several stacks can run at the same time, each doing its own job — one driving, one watching a sensor, one keeping the display up to date.
How it is done
Give each stack its own hat block. Every stack beginning with when program starts starts at the same instant — not one after another — and from then on they run alongside each other.
Nor is it limited to two. Below, three stacks run together: a Medium Motor turning an attachment, the status light flashing, and the drive base rolling. Watch the arrows at the top — they all begin at once, and no stack waits for any other.
when program starts :: events hat
[A v] start motor [clockwise v] :: motors
when program starts :: events hat
forever
set status light to [green v] :: display
wait (0.5) seconds
set status light to [red v] :: display
wait (0.5) seconds
end
when program starts :: events hat
start moving [straight: 0] :: movement
Written down they have to go one under another, because a page is a column — but that is an accident of paper. On the Brick they sit side by side, and nothing in the first stack happens before anything in the third.
The rule: one owner per thing
Parallel stacks go wrong when two of them try to control the same thing. Use the switch below to take the wheels away from the third stack and point it at motor A, which the first stack is already driving.
the program starts — all of these begin here
stack 1 · Medium Motor
when program starts
A start motor clockwise
stack 2 · status light
when program starts
forever
set status light to green
wait 0.5 seconds
set status light to red
wait 0.5 seconds
stack 3 · drive base
when program starts
start moving straight: 0
One stack, one jobAll three at once
Three stacks, each with its own hat block. All three start the moment the program starts — none of them waits for the others.All three are running in the same instant: the Medium Motor is turning, the light is flashing, and the drive base is rolling.Each stack owns one thing and never touches another stack's job. That is the rule that makes this work.Finished. All three jobs ran the whole time, and none got in another's way.
three stacks, three jobs
Every stack is highlighted at the same moment on purpose — that is what running in parallel looks like. The switch above changes only what the third stack controls.
With one owner each, all three stacks are highlighted at the same instant and all three jobs get done. With two owners, motor A is handed contradictory orders hundreds of times a second and shivers instead of turning — and notice the second cost, which is easy to miss: the wheels now have nobody driving them. A stack that goes to fight over someone else’s motor has abandoned its own job. Nothing reports an error either way; as far as the Brick is concerned every stack is working perfectly. The same happens to a display line or a variable that two stacks both write to.
The discipline is simple: give each stack sole ownership of what it controls. One stack owns the motors, another owns the screen, another watches the sensors and tells the others what it found — which is what broadcasting is for.
ComponentSensing5 min
The Touch Sensor
The Touch Sensor is the simplest input the EV3 has: a button that is either pressed or not. That sounds trivial, but it is how a robot knows it has hit a wall, reached the end of a track, or been told to start by a person.
released
pressed
The red button out, and the same sensor with it pushed in. These two states are the entire output of this sensor — there is nothing in between.
Blocks reference
Block
What it does
wait until <[1 v] is pressed? :: sensors>
Holds the program here until somebody presses the sensor.
<[1 v] is pressed? :: sensors>
Reports true or false. Drop it into a condition to make a decision rather than a wait.
[1 v] when [bumped v] :: events hat
Starts a whole stack of its own. The dropdown chooses the moment: pressed, released or bumped.
Three different events
A button is not only “pressed”. One press is three things: the moment it goes down, the time it stays down, and the moment it comes back up. Watch what a single press does to three programs at once.
when program starts
forever
if 1 is pressed? then
change count by 1
versus two hat blocks
1 when pressed
1 when bumped
0is pressed? in a loop0when pressed0when bumped
In a loop: 0 answers from one pressBumped: exactly one
Nobody is touching the sensor. All three programs are watching it.A finger presses the button. Watch the red button go in — a couple of millimetres is the sensor's entire movement.The finger is still down. The loop checking «is pressed?» has already run hundreds of times, and every one of them counted.The finger lifts. Only now does «bumped» count, because bumped means pressed AND released.One press. Three completely different answers.Finished. The same press, counted three ways.
released
The middle counter is the one that surprises people. Nothing is wrong with it — a loop really does check that fast, and every check really is a separate answer.
Nothing there is broken. A loop really does get round hundreds of times a second, and each time it asks is pressed? the honest answer is still yes — so if that loop plays a sound or counts something, it does it hundreds of times from one finger. The two hat blocks each fire once, and they fire at different moments: pressed the instant the button goes down, bumped only when it comes back up.
The three options, and what each is for:
Pressed — the button is down right now. Good for “hold to run”.
Released — it is up again. Good for acting when somebody lets go.
Bumped — pressed and released. This is what you want for “click to start”, because it will not fire repeatedly while a finger stays down.
The classic bumper
when program starts :: events hat
set movement motors to [B v] and [C v] :: movement
start moving [straight: 0] :: movement
wait until <[1 v] is pressed? :: sensors>
stop moving :: movement
The robot drives until something presses the sensor. Note that the movement is started unmeasured on purpose — the sensor decides when to stop, not a distance.
Why it matters
Touch sensors are everywhere in machines you cannot see into: a lift knows the doors are shut, a printer knows the lid is closed, a washing machine will not spin until it is latched. They are safety devices as much as inputs.
Say this back before moving on: “Each hat starts its own stack, and they all run at the same time.”
What’s in this build 4 min
Four parts with cables. And again, you have to tell us which motor it is. There is no build guide and no checked parts list.
Part
What it is doing here
EV3 Intelligent Brick
Runs the program. It is also the heaviest thing in the frame. So it stops the model rocking off the table when the ship swings.
One motor — you decide which
Turns the driving tyre. It goes in port A. Every program below says A.
Touch Sensor ×2
Left and right. The two look the same. Only the port tells them apart. You learned that with the Machine Gun.
The driving tyre (no cable)
Presses on the ship and pushes it along. It only works where it touches. That is why timing matters so much.
Find the ship’s own rhythm
Turn the Brick off. You did this with the Clock Ticking.
Pull the ship to one side and let go. Do not push it.
Time ten full swings. Over and back is one swing. Divide by ten. That is the ship’s period: how long one swing takes.
Watch where the ship is slowest. It is at the two ends, where it stops and turns round. It is fastest at the bottom.
Now decide, before you touch a button. You want a bigger swing. Should you push at the bottom, as it moves away from you? Or at the top?
Step 4 is the whole game. Push the way it is moving, when it is going fastest. Push against it, and you slow it down.
Ports — and the rule 4 min
Sensors go in ports 1, 2, 3, 4. Motors go in ports A, B, C, D. You cannot swap them. If you do, nothing warns you. The robot just will not work.
Part
Port
Why this one
The motor (drives the tyre)
A
One working motor goes in A, like all course.
Touch Sensor — left
1
Touch is always port 1 in this course.
Touch Sensor — right
2
The second one uses the Gyro’s port, like the Machine Gun. There is no Gyro here.
Check your own build now:
Motor cable in A. A letter.
Label the two sensor cables 1 and 2 with tape before you plug them in, just like last lesson. Left is 1.
Is the driving tyre really touching the ship? It must press hard enough to grip. But the ship must still swing freely when the motor is off. Getting this right is the trickiest part of the build.
Swing the ship by hand all the way. Does anything catch? There must be nothing in the way at the top. That is where you are trying to get it.
Connect the Brick 4 min
Two routes, and either is fine. USB is the reliable one and the one to fall back on when a room’s Bluetooth is busy; Bluetooth leaves the robot free to move, which some models need.
▶How to connect the BrickUSB and Bluetooth, step by step, with a photograph of every screen. Open it if you have not done this before — or if pairing is not working.Show meHide
USB — the reliable one
Switch the Brick on with the dark grey centre button.
Cable into the Brick’s PC port — the small square socket beside the numbered ports, not one of the numbered ones.
Other end into the computer.
Bluetooth — name it first
Do these in order. Naming the Brick after you go looking for it in the list is how groups end up driving each other’s robots.
Name your Brick. On the Brick: Settings (the spanner) → Brick Name. Type something nobody else will pick, then press the tick. Every Brick is called EV3 until somebody changes it.
Turn Bluetooth on. Settings → Bluetooth. Tick Bluetooth and Visibility. Leave iPhone/iPad/iPod unticked.
Connect from EV3 Classroom. Click the Brick icon at the top of the programming area, find your Brick by name, and click Connect.
Say yes on the Brick. It asks “Connect?” with the computer’s name — choose the tick, then accept the passkey, which is already 1234.
Where to read it. The name sits in the bar across the very top of the screen, on every screen — so you can check which Brick you are holding at any moment without going into a menu. This one is EV3VE. A Brick nobody has renamed says EV3.Step 3, and the reason step 1 exists. Three Bricks in range — read the name before you click Connect. Pairing with the wrong one is not an error: it works perfectly, on somebody else’s robot.
Step 2.Bluetooth switches the radio on; Visibility is what lets the computer find you. With Visibility off your Brick works perfectly and simply never appears in the list.Step 4. Look at the Brick. It asks whether to accept and names the computer. Choose the tick.Then the passkey, already 1234. Press the tick again and you are connected.
The two failures, every class, every time. The Brick has gone to sleep while you were building — press the centre button to wake it. Or you have paired with the group at the next table, which is why the name matters.
The long version, including Port View and how to read the port tiles, is in the Brick & Bluetooth guide.
Keep every cable out of the ship’s path. If you get it right, this model swings in a full circle. A cable in the way will stop it just as you are about to win.
Confirm the connection 2 min
Check the Brick icon: connected, or not.
Port A shows a motor. Note which kind.
Ports 1 and 2 both show a Touch Sensor.
Press the left button and check that tile 1 changes. Then the right, and tile 2. Are they swapped? Swap the cables now.
Swapped cables do not look like a bug. The ship just will not swing, however hard you try. Every push lands on the wrong side.
Change it and test 8 min
One change at a time, and guess before each run. Count how many taps it takes to get over the top. That is your score. Lower is better.
Change both 120 values to 60. Smaller pushes. Do you need more taps or fewer? Is the ship easier or harder to control? Guess first.
Now 240. Bigger pushes. Most groups find this is worse, not better. A long push is still going when the ship turns round. So the end of the push works against you.
Back to 120, and change the speed in the first stack to 100 %. A faster push, in less time. Better or worse?
Change the [2] hat to [1]. Now both stacks wait for the same button. Guess what one press does now. Two stacks both grab port A at once, and it is a mess. This is the one-boss-per-motor rule, broken on purpose.
Put it back and add a fourth stack: when [center v] button [pressed v] with stop [all v] under it. Now you have an emergency stop. It works whatever else is going on.
Keep step 5 for good. An emergency stop is the perfect job for its own stack. It must work whatever the rest of the program is doing. A program with just one stack can never do that.
Anything that must work at any moment goes in its own stack.
Build it 15 min
Build the model before you read any further. Everything after this is about making it do something, and none of it will make much sense with nothing on the table in front of you.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Check the finished build against the picture before you switch anything on. A motor mounted the wrong way round is far easier to spot now than it is to debug later, when it looks like a program fault.
This is what you are building: the Crazy Pirate Ship.
Make it move 10 min
Three stacks, six blocks. Look at the shape before you read the words. There are three separate hats, with a gap between each. They are not one program that runs down. They are three programs that run together.
when program starts :: events hat
[A v] set speed to (60) % :: motors
[1 v] when [pressed v] :: events hat
[A v] run [clockwise v] for (120) [degrees v] :: motors
[2 v] when [pressed v] :: events hat
[A v] run [counterclockwise v] for (120) [degrees v] :: motors
The first stack runs once and sets the speed. The other two wait for ever, each for its own button.
How the Brick handles this:
Press the green flag. The first stack runs its one block and ends. The speed is now set.
The other two stacks do not run. They are armed. That means they are ready, waiting for their sensors.
Press the left button. The second stack runs on its own. The first stack has nothing to do with it.
Press the right button. The third stack runs.
Press left again, and the second runs again. And again. A hat does not get used up.
Now use it. Start the ship swinging gently by hand. Each time it passes the bottom, tap the button that pushes it the way it is already going. Small pushes, in time. Watch the swing grow.
What success looks like: the swing gets bigger over eight or ten good taps. In the end, the ship goes over the top. It will take a few tries. That is normal. You are not failing.
Does the swing never grow? You are almost sure to be pushing at the wrong moment. You are not pushing too softly. Try getting it wrong on purpose. Push against the movement for a few swings. Watch the swing shrink. Once you can stop it on purpose, you know the right moment.
Challenges 27 min
Work through them in order — each is harder than the last. The extra challenge comes after all three, and it is meant to make you plan before you build.
Challenge 1
Get it over the top, and count the pushes. Use well-timed taps. Bring the ship all the way round at least once. Then do it again and count how many pushes it took. Report your best count. Can you not get it round at all? Then report your biggest swing angle. Say what is stopping you.
Challenge 2
Add an emergency stop on its own stack. Use a Brick button. It must stop the drive, whatever else is going on. Then prove it works. Press it in the middle of a push, not between pushes. Explain in one sentence why it needs its own stack.
Challenge 3
Prove that timing beats force. Push at the wrong moment, on purpose. Bring a big swing down to almost nothing. Time how long that takes. Then do the opposite, starting from still. Report both times. Say the rule you have shown, in one sentence.
Extra challenge
Build a ride you could hand to someone to run, controls and all.
Somebody who has not practised must find your Crazy Pirate Ship easy to drive. It needs two clearly labelled controls. It needs an emergency stop that always works. Something on the Brick must tell the driver what the machine is doing. The driver should be able to build up a swing. Then they bring it safely back down to still.
Plan on paper before you build. Draw every stack you will write, and what starts it. Then check the one rule that will catch you out. Does any motor have more than one stack trying to drive it?
Answer two questions when you show it. Why does your emergency stop work, no matter where the rest of the program is? And what would happen if two of your stacks started at the same moment? Have you made that impossible, or just unlikely?