Scratch 2.0 also allows the creation of custom blocks, allowing code to be encapsulated and used (possibly multiple times) in a project. 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. Each apple sprite clone then follows its ‘when i start as clone’ script. 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. Clones are instances of a particular sprite that inherit all of the scripts of the main sprite. One of the main new features of Scratch 2.0 is the ability to create clones of sprites. Scratch 2.0 also offers some additional features and improvements over Scratch 1.4. In the example below, the Scratch cat will say “Pressed” only when the button is being held down. 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. To give an example, the entire code for repeatedly flashing an LED connected to GPIO pin 2.0 is now: In the ‘More Blocks’ section you should now see the additional blocks for controlling and responding to your Pi GPIO pins. You should then select the ‘Pi GPIO’ extension option and click OK. To add GPIO functionality, first click ‘More Blocks’ and then ‘Add an Extension’. 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. This means that your Scratch projects can light LEDs, sound buzzers and use input from buttons and a range of sensors to control the behaviour of sprites. Controlling GPIO with Scratch 2.0Īs with Scratch 1.4, Scratch 2.0 on the Raspberry Pi allows you to create code to control and respond to components connected to the Pi’s GPIO pins. This is great news for clubs and classrooms, where children can now use Raspberry Pis instead of connected laptops or desktops to explore block-based programming and physical computing. The most recent update to Raspbian includes the app, which makes Scratch 2.0 available offline on the Raspberry Pi. 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 other exciting new features.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |