5. Chapter Two Electronic Button Switch

5.1. Project 05.0_Two_Electronic_Button_LED, 05.1_Squash0 and 5.2_Jump

5.1.1. Components

Raspberry Pi (with 40 GPIO) x1

GPIO Extension Board & Ribbon Cable x1

Breadboard x1

Push Button x2

button-small

Jumper Wire

jumper-wire

Resistor 10kΩ x4

res-10k

5.1.2. Circuit

Schematic diagram

scratch_t_button_Sc

Hardware connection. If you need any support,please feel free to contact us via:

support@freenove.com

scratch_t_button_Fr

5.1.3. Code

5.1.3.1. Two_Electronic_Button_LED

Load the code to scratch3.

Freenove_Kit/Code/Scratch3/04.1_Keyboard_RGBLED.sb3

Click the green flag. Then press two button switches to observe the change.

There are two balls. We need write two sections of code for two GPIOs.

../../../_images/scratch_t_button_code.png

5.1.3.2. Squash

Load the code to scratch3.

Freenove_Kit/Code/Scratch3/05.1_Squash.sb3

Click the green flag. Press the two button swtiches to move the green paddle.

There are two sprites moveing. So we need write two section of code. One is for ball. Another is for paddle.

../../../_images/scratch_t_button_code1.png

Pick random “range”. It can ne any one of 145~180, like: 145 150 180 146.

5.1.3.3. Jump

Load the code to scratch3.

Freenove_Kit/Code/Scratch3/05.2_Jump.sb3

Click the green flag. Press the two button swtiches to make the sprite go through the line and not touch the other items..

../../../_images/scratch_t_button_code3.png

A or B or C. One of them is true. The whold result would be true. It mean the sprite1 cannot tounch any of others.