{"id":33552,"date":"2017-06-27T12:21:26","date_gmt":"2017-06-27T11:21:26","guid":{"rendered":"https:\/\/www.raspberrypi.org\/?p=33552"},"modified":"2021-09-19T15:06:02","modified_gmt":"2021-09-19T14:06:02","slug":"scratch-2-raspberry-pi","status":"publish","type":"post","link":"https:\/\/www.raspberrypi.org\/blog\/scratch-2-raspberry-pi\/","title":{"rendered":"Scratch 2.0: all-new features for your Raspberry Pi"},"content":{"rendered":"
We’re very excited to announce that Scratch 2.0 is now available as an offline app for the Raspberry Pi! This new version of Scratch allows you to control the Pi’s GPIO (General Purpose Input and Output) pins, and offers a host of\u00a0other exciting new features.<\/p>\n
<\/p>\n
The\u00a0most recent update to\u00a0Raspbian includes the app, which makes Scratch 2.0 available offline on the Raspberry Pi. This is great news for clubs and classrooms,\u00a0where children can now use Raspberry Pis\u00a0instead of connected laptops or desktops to explore block-based programming and physical computing.<\/p>\n
As with Scratch 1.4, Scratch 2.0 on the Raspberry Pi allows you to create\u00a0code to control and respond to components connected to the Pi’s GPIO pins. This means that your Scratch projects can light LEDs, sound buzzers and use input from buttons and a range of sensors to control\u00a0the behaviour of sprites. Interacting with GPIO pins in Scratch 2.0 is easier than ever before, as text-based broadcast instructions have been replaced with custom blocks for setting pin output and getting current pin state.<\/p>\n
<\/p>\n
To add GPIO functionality, first click ‘More Blocks’ and then ‘Add an Extension’. You should then select the ‘Pi GPIO’ extension option and click OK.<\/p>\n
<\/p>\n
In the ‘More Blocks’ section you should now see\u00a0the additional blocks for controlling and responding to your Pi GPIO pins. To give an example, the entire code for repeatedly flashing an LED connected to GPIO pin 2.0 is now:<\/p>\n
<\/p>\n
To react to a button connected to GPIO pin 2.0, simply set the pin as input, and use the ‘gpio (x) is high?’ block to check the button’s state. In the example below, the Scratch cat will say “Pressed” only when the button is being held down.<\/p>\n
<\/p>\n
Scratch 2.0 also offers some additional features and improvements over Scratch 1.4. One of the main new features of Scratch 2.0 is the ability to create clones<\/b> of sprites. Clones are instances of a particular sprite that inherit all of the scripts of the main sprite.<\/p>\n
The scripts below show how cloned sprites are used — in this case to allow the Scratch cat to throw a clone of an apple sprite whenever the space key is pressed. Each apple sprite clone then follows its \u2018when i start as clone\u2019 script.<\/p>\n
<\/p>\n
The cloning functionality avoids the need to create multiple copies of a sprite, for example multiple enemies in a game or multiple snowflakes in an animation.<\/p>\n
Scratch 2.0 also allows the creation of custom blocks<\/b>, allowing code to be encapsulated and used (possibly multiple times) in a project. The code below shows a simple custom block called \u2018jump\u2019, which is used to make a sprite jump whenever it is clicked.<\/p>\n
<\/p>\n
These custom blocks can also optionally include parameters, allowing further generalisation and reuse of code blocks. Here\u2019s another example of a custom block that draws a shape. This time, however, the custom block includes parameters for specifying the number of sides of the shape, as well as the length of each side.<\/p>\n
<\/p>\n
The custom block can now be used with different numbers provided, allowing lots of different shapes to be drawn.<\/p>\n
<\/p>\n
Another feature of Scratch 2.0 is the addition of code blocks to allow easy interaction with a webcam or a microphone. This opens up a whole new world of possibilities, and for some examples of projects that make use of this new functionality see\u00a0Clap-O-Meter<\/a> which uses the microphone to control a noise level meter, and a Keepie Uppies<\/a> game that uses video motion to control a football. You can use the Raspberry Pi or USB cameras to detect motion in your Scratch 2.0 projects.<\/p>\n Other new features include a vector image editor\u00a0and a sound editor, as well as lots of new sprites, costumes and backdrops.<\/p>\n Scratch 2.0 is available in the latest Raspbian release<\/a>, under the ‘Programming’ menu. We’ve put together a guide for getting started with Scratch 2.0 on the Raspberry Pi online<\/a> (note that\u00a0GPIO functionality is only available via the desktop version).\u00a0You can also try out Scratch 2.0 on the Pi\u00a0by having a go at a project from the\u00a0Code Club projects site<\/a>.<\/p>\n As always, we love to see the projects you create using the Raspberry Pi. Once you’ve upgraded to Scratch 2.0, tell us about\u00a0your projects via\u00a0Twitter<\/a>, Instagram<\/a> and Facebook<\/a>, or by leaving us a comment below.<\/p>\n","protected":false},"excerpt":{"rendered":" We’re very excited to announce that Scratch 2.0 is now available as an offline app for the Raspberry Pi! This new version of Scratch allows you to control the Pi’s GPIO (General Purpose Input and Output) pins, and offers a host of\u00a0other exciting new features. Offline accessibility The\u00a0most recent update to\u00a0Raspbian includes the app, which…<\/p>\n","protected":false},"author":32597,"featured_media":33928,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,3879],"tags":[],"home_page_category":[],"home_page_card_color":[],"class_list":["post-33552","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","category-foundation"],"acf":[],"featured_image_src":"https:\/\/www.raspberrypi.org\/app\/uploads\/2017\/06\/cover-1.png","author_info":{"display_name":"Rik Cross","author_link":"https:\/\/www.raspberrypi.org\/blog\/author\/rikcross\/"},"yoast_head":"\nUpdate your Raspberry Pi for Scratch 2.0<\/h2>\n