(Updated, expanded)
m (Fixexd blocks)
Line 15: Line 15:
 
Activating a motor when the distance sensor is activated
 
Activating a motor when the distance sensor is activated
 
<scratchblocks>
 
<scratchblocks>
when distance [< v] (10)
+
when distance [< v] (10)::wedo
turn [motor v] on for (0.25) seconds
+
turn [motor v] on for (0.25) seconds::wedo
 
</scratchblocks>
 
</scratchblocks>
 
Reporting the distance when it is less than a specified value
 
Reporting the distance when it is less than a specified value
 
<scratchblocks>
 
<scratchblocks>
when distance [< v] (50)
+
when distance [< v] (50)::wedo
repeat until <(distance) > (50)>
+
repeat until <(distance::wedo) > (50)>
say (distance)
+
say (distance::wedo)
 
</scratchblocks>
 
</scratchblocks>
  

Revision as of 01:33, 31 December 2019

When Distance () ()
[[when distance [< v] (50)]]
Category LEGO WeDo
Type Hat
Introduced in 2.0

The When Distance () () block is a LEGO WeDo block and a Hat block. The block activates when the distance is less than or greater than the specified value, depending on the argument selected from the drop-down menu. Prior to Scratch 2.0, this block did not take a comparison argument but remained with a less-than sign constantly.

This block can only be used with a LEGO WeDo Construction Set.

Uses

Some example uses for this block are:

Activating a motor when the distance sensor is activated

when distance [< v] (10)::wedo
turn [motor v] on for (0.25) seconds::wedo

Reporting the distance when it is less than a specified value

when distance [< v] (50)::wedo
repeat until <(distance::wedo) > (50)>
say (distance::wedo)

See Also