Shaking Hands with Marty
As

With the arm and hand raised, we actually need to shake hands. That will mean moving the arm up and down multiple times. A repeat block will help us here!

In my version, I've made Marty shake his hand 4 times, but that's up to you! Once the handshake is done, it's probably sensible to put the arm down again,

Getting Started - Handshake Movements
There will be two main bits to this - moving and sensing. First off, lets sort out the movement bit! The first bit of any handshake is to proffer a hand, so lets activate Marty and raise the right hand,
Adding Some Emotion
That's the basic arm movements, but wouldn't it be nice if Marty's eyebrows moved too? We can do that!

Getting Interactive
We've got the moves, but Marty really needs to be able to tell when to shake hands. To do that, we're going to use the motor current sensors to detect when there is some force on the arm,
Reading Motor Currents
Let's make a variable called right arm torque,

But, the motor current sensors give very small numbers - try pushing Marty's right arm a bit and double-clicking the piece of code we just added and see what value you get displayed on the stage section of the Scratch interface. Let's make that variable a bit bigger!

We're going to want to update this variable often and we don't want to have to code the calculation more than once, so let's define a function to update the sensor values for us,

Putting it Together
Ok then! Let's use our shiny new variables and update sensors function to make the handshake interactive!

- We wait for a second after moving the arm to give the motors a chance to settle
- We call update sensors before entering the loop to make sure that we're not using an old sensor value at the start
- We use a repeat until block to loop until Marty detects an amount of force on the right arm. In this case we have set the threshold to be 3, but try varying it to see what happens!
Knowing When to Start
But how does Marty know when to start the handshake? That's up to you, but I've made mine so that touching either arm will make Marty offer to shake hands. To do that I made another variable to store the left arm torque value and added another block to the update sensors function we made earlier,

To keep things tidy, I moved the actual handshake-y bit into its own function and made a seperate block of code to keep track of sensor readings and when to start a handshake!

I've also added a cheeky wiggle at the end...

Scratch Project File
Making it Bigger
You don't have to stop. there! I have an even better handshake with my Marty, it has high fives and sound and everything! It looks like this,
