Events

"Event" blocks in EV3 are like special buttons that you can program to make your robot do specific actions when certain events happen. They add a lot of fun and interactivity to your robot's behavior!

event-meaning

We are going to explore these blocks:

event-meaning

-> "When the program begins": it's the most common used block.

-> We can also use the sensors to start the program, as long as it meet the condition.

-> The broadcast block are to send message from one code to the other.


The 5 buttons of the brick:

event-brick-intro

There are 5 buttons you can press and starts the program.

The "no" means: no button press (just like "when the program starts")

The "center" and "left" button

When "center" button is pressed

Center

Notice that the video/image is x2 speed.

2-event-center

1- The robot wait for you press "center" buttom

2-Robot move forward 300 degrees at the speed of 30%

3- Motor A move 200 degrees clockwise at the speed of 20%

4-Robot move forward 400 degrees at the speed of 30%

5- Motor A move 100 degrees counter-clockwise at the speed of 20%

6-Robot move backward 300 degrees at the speed of 30%

7- Stop and Exit program

When "left" button is pressed

left
3-event-left

1- The robot wait for you press "left" buttom

2-Robot move forward 1000 degrees, left wheel at the speed of -60% and right wheel at the speed of 0%

-> Robot make a pivot turn of 1000 degrees.


The sensors

Ultrasonic Sensor

a event
1-event-ultra

1- The robot wait for ultrasonic sensor sense "less than 15cm"

2-Robot move forward 1000 degrees, left wheel at the speed of -60% and right wheel at the speed of -20%

-> Robot make a pivot turn of 1000 degrees.

Color Sensor

a event (4)
5-event-color-sound

1- The robot wait until color sensor read "green"

2- Robot say "Green". And then say "Go"

3-Robot "starts moving" backward at the speed of 40%

4- Until color sensor read "red"

5- Robot stop moving

6- Robot say "Red". And then say "Stop"

7- Stop and Exit program

Touch Sensor + display

a event (3)
4-event-face

1- The robot wait until touch sensor is "pressed"

2- Robot display robot "smile" face for 1 second

3- Robot display robot "wink" face for 1 second

4- Robot display robot "smile" face for 1 second

5- Robot display robot "wink" face for 1 second

6- Stop and Exit program


Broadcast

Remember this code from Control "wait" block?

6-event-no-Broadcast

We are going to use broadcast.

Notice: you can change the name of the broadcast.

a event (5)

-> Broadcast named "broadcast1" is Motor A moves clockwise of 250 degrees at the speed of 75%

7-event-broadcast

1- Robot move 450 degreees forward at the speed of 50%

2- Robot wait for 1 second

3- Code broadcast receive message called "broadcast1"

which it's Motor A moves clockwise of 250 degrees at the speed of 75%

Observations: Why is "Event" important for programming?

Time for a quiz!

Question goes here

Challenge for you

a event (6)

I want you to use:

-> Event for gyro Sensor block. Robot move toward the left

-> "Reset angle" block

-> Wait for 1 second

-> Stop and exit program

-> Speed is 50% and robot move forward for 500 degrees.

-> The angle is 45 degrees

event-you
event-you-gyro-45

Notice that you need to spin a bit the robot to the left, so that the gyro count 45 degrees.

If it didn't work, it might be because of the inequality symbol.