Can I Buff a Scratch Out of My Drawing Tablet

force___flex_scratch_wiki_main.png

source: Wikimedia Commons

In this guide we'll delve into the popular programming language Scratch.

Scratch is a block-based language geared for beginners that lets you create your own interactive stories, animations, games, music, and art.

Scratch is easy to use and requires no prior coding experience!

First we'll do a walkthrough of the basics.

Next we'll cover the updates in the 3rd and newest edition of the language which was released January 2, 2019.

Lastly we'll do some digital painting inside Scratch using a Circuit Playground Express as our "paintbrush" and "palette". See below!

Adafruit Parts

1 x USB cable

USB A to Micro-B (Plugs into computer to program the CPX)

Optional

The quickest way to get started with Scratch is to jump right in! The programming language is web-based which means there is no downloading necessary. Just head to the website below.

After entering the Scratch site, click the orange "Start Creating" button.

You will then be taken to the Scratch project editor. This is where all the coding happens!

Follow the short tutorial to learn the basics of how "sprites" work in Scratch.

force___flex_Screen_Shot_2019-01-15_at_5.31.02_PM.png

Scratch is a "block-based" programming language. This means instead of writing lines of code to program, we use "blocks". Each block has a specific category that describes what its purpose is. Sprites are the objects that perform actions in a project and these blocks tell the sprites what to do. Code blocks can also tell a stage or backdrop how to behave.

The different types of code blocks:

  • force___flex_Screen_Shot_2019-01-16_at_3.36.54_PM.png
  • Define the movement of sprites
  • force___flex_Screen_Shot_2019-01-16_at_3.37.05_PM.png
  • Change the appearance of sprites. Gives the ability to change costumes and apply graphic effects.
  • force___flex_Screen_Shot_2019-01-16_at_3.37.15_PM.png
  • Play audio by recording sounds, using Midi notes and more.
  • force___flex_Screen_Shot_2019-01-16_at_3.37.31_PM.png
  • Trigger scripts or series of code blocks. Consists mainly of hat blocks which start a script.
  • force___flex_Screen_Shot_2019-01-16_at_3.37.44_PM.png
  • Dictate the flow of a project. Provide mechanism for "looping" different blocks and scripts.
  • force___flex_Screen_Shot_2019-01-16_at_3.37.58_PM.png
  • Let multiple sprites interact with themselves and/or the stage. Can determine how two sprites collide for example.
  • force___flex_Screen_Shot_2019-01-16_at_3.38.07_PM.png
  • Allow various mathematical functions within a project. Can be used to modify variables and strings.
  • force___flex_Screen_Shot_2019-01-16_at_3.38.17_PM.png
  • Used to store data in projects, like a name or a score.

My Blocks

  • force___flex_Screen_Shot_2019-01-16_at_3.38.32_PM.png
  • You can create your own blocks!

Extension Blocks

The Scratch user interface is the area on your screen where the Scratch program exists. The screen is divided into multiple sections or "panes" which have different functions from picking blocks to code with, to coding, to seeing your code in action. We will go through the different elements of the interface.

force___flex_Screen_Shot_2019-01-16_at_12.07.39_PM.png

The Block Palette

  • force___flex_Screen_Shot_2019-01-16_at_11.02.35_AM.png
  • The block palette is where all the code blocks exist. Blocks are color coded by category. These blocks can be dragged to the scripting area to either code sprites or the stage.

The Script Area

  • force___flex_Screen_Shot_2019-01-16_at_11.03.23_AM.png
  • The scripts area is where our code is dragged to and assembled.

The Stage Area

The Sprite Info Pane

  • force___flex_Screen_Shot_2019-01-16_at_11.03.37_AM.png

The sprite info pane is where we can find info about our sprites as well as manipulate them. Access this pane by clicking on the thumbnail of the desired sprite. This area also allows us to delete and create new sprites.

The Costume/Backdrop Pane

The Sounds Pane

  • force___flex_Screen_Shot_2019-01-16_at_11.15.42_AM.png
  • The last tab in the top left area of the interface allows us to crate and manipulate sounds. You can even record your own!

Toolbar and Tutorials

  • The toolbar on the top of the screen allows us to load and save projects as well as undo the deletion of sprites.
  • Find a variety of tutorials on how to do just about anything in Scratch by clicking the "tutorials" button!

Workflow and mistakes

  • Copy and paste code blocks to save time.
  • Be careful when creating and deleting sprites! The code blocks you create tell the associated sprite what to do. Thus when you delete a sprite you are deleting the code that tells it what to do.

Deleting a sprite will delete all the code associated with that sprite!

  • force___flex_Screen_Shot_2019-01-16_at_11.58.01_AM.png

If you accidentally delete a sprite, click edit on the tool bar then click "Restore Sprite" to bring your code back to life!

Troubleshooting

  • Right click a block for help.
  • Visit the Scratch wiki for more help.
  • There's a whole community of Scratchers that have come across a multitude of issues and would also love to help.
  • To join the community make an account!

Scratch 3.0 includes a new sound editor, new sprites, new programming blocks, and much more.

A new build

Scratch was originally built with Adobe Flash which is going away soon so the new update is built in HTML5 and a Javascript library called React.

What does that mean for us?

Scratch can now be used on tablets and almost all hardware, like Raspberry Pi for example!

Scratch Extensions

Scratch extensions is a new feature that allows for Scratch programs to talk to external hardware and online resources. Micro:bit even has its own extension!

Other updates per the Scratch Wiki:

      • Stage is moved to the top right.
      • New modern look and design.
      • Some color changes to blocks. Events Blocks are the color of the Scratch 2.0 Control Blocks, and control blocks are a bit lighter than the old events blocks
      • More Blocks has been renamedMy Blocks, and is a shade of light red
      • Some default inputs (the inputs that show up in theBlock Palette are different)
      • New Paint Editor and Sound Editor
      • Pen ,Video Sensing, andMusic blocks are now extensions
      • You can now make and play projects on tablets and play them on phones, but currently you cannot edit projects on mobile phones
      • Several extra options for the "touching ()?" boolean, including "any edge", "mouse-position", and "left edge"
      • Different fonts: Sans Serif (thin Helvetica), Serif (Times), Handwriting, Marker, Curly, Pixel, Chinese, Japanese, and Korean
      • The vector paint editor is now the default editor
      • The Video Sensing blocks are in an extension
      • New extensions:Text to Speech,Translate,Micro:bit, and Lego Mindstorms EV3.
      • Internet Explorer will not be a supported browser
      • PicoBoard  andLEGO WeDo 1.0 are not supported
      • The addition of a pause button like inPhosphorus andSulfurous
      • New blocks!! (below) Click here to learn more about the functionality of these blocks.

force___flex_image.png

In this demo we will create a simple draw program in Scratch.

Next we will create a program in MakeCode that will allow a Circuit Playground Express (CPX) to control the mouse and keyboard functions that we define in Scratch.

Lastly we create a masterpiece!

The best way to learn a new language is to start making with it, so let's go!

Find the Scratch code to this project below. Feel free to follow along or access the code for yourself!

After clicking the link above, you'll be taken to the project page. Once there, click see inside to access the code.

force___flex_Screen_Shot_2019-01-17_at_1.00.14_PM.png

Create a sprite for the pen

The first thing we want to do is make a new sprite for our pen. This sprite will not only be the visual representation of our painting tool but it will also hold all the associated code.

Adding the pen extension blocks

Setting up the program

Forever loop

  • force___flex_Screen_Shot_2019-01-17_at_1.13.50_PM.png
  • In a forever loop, we add a point towards mouse-pointer block.
  • Next, goes apen down block.
  • Then drag a move x steps block, dragging in the variable stepSize from the variables blocks in place of the number.
  • Now we create a series of if statements that check for the color-counter value which will tell the program when to switch colors and what color to switch to.
  • Each time the character c is typed on the keyboard, the value of color-counter increases by 1 (we will get to this next). However, with the last if statement, when the value reaches above 6, it is reset back to 1.
  • force___flex_Screen_Shot_2019-01-16_at_5.00.10_PM.png
  • The last few blocks of code define functions for pressing keys e (erase) and c (color).
  • When e is pressed, we erase the board. In the next section, when we code the CPX, we tell it to send the character e when it is shaken.
  • When c is pressed we increase the value of color-counter by 1. Later this will get translated into: when button A is pressed on the CPX, send the character c.

Test it out!

Now that the Scratch program is finished, test out the code in the stage by clicking the green flag to start. Move the mouse around to guide the pen. Press c to change colors and e to erase the board.

force___flex_Screen_Shot_2019-01-17_at_1.35.22_PM.png

What is Circuit Playground Express (CPX)?

The Circuit Playground Express is an easy way to get started learning electronics and coding. It's filled with tons of fun lights and sensors! The CPX is what we'll use to control the mouse and keyboard to draw in our new Scratch program. Head here to learn more about the CPX.

force___flex_image.png

What is MakeCode?

MakeCode is a web-based code editor for physical computing made by Microsoft.

It is almost identical to Scratch in design, however it is mainly for programming hardware like the CPX rather than a sprite on a computer screen.

More on MakeCode for Adafruit boards here.

Create a New Project with MakeCode

Head over to https://makecode.adafruit.com/ and create a new project.

Click the button below to access the code for this project.

force___flex_Screen_Shot_2019-01-17_at_2.00.56_PM.png

Add the Keyboard and Mouse Extensions in MakeCode

Follow this guide on how to add these extensions to MakeCode. They will allow us to use the CPX to act as a mouse and a keyboard!

force___flex_Screen_Shot_2019-01-17_at_2.05.19_PM.png

The NeoPixel Palette

  • force___flex_Screen_Shot_2019-01-17_at_2.01.03_PM.png
  • In an on start loop, set the colors of the NeoPixels on the CPX to the according colors. This is so the user knows which colors they have to choose from.

Coding with the accelerometer

1 G (one gee) is equivalent to Earth's gravitational pull at a resting point.

The CPX's accelerometer senses the gravity it feels in any given direction on the x, y or z axis. The value it senses is anywhere from 0 to 1023 mg (miligravities). 1G = 1000 miligravities.

Learn more about the accelerometer on the Circuit Playground Express here.

  • force___flex_Screen_Shot_2019-01-16_at_5.02.07_PM.png
  • In a forever loop, we create an if else statement that describes how the mouse should move when the CPX is tilted forwards, to the right, backwards, or to the left.
  • If the accelerometer senses any more that 500mg in any direction, the mouse will move in that direction.

Sending keyboard info

  • force___flex_Screen_Shot_2019-01-17_at_2.01.19_PM.png
  • When button A is clicked, the CPX sends the character c for color change.
  • When the CPX is shaken, the CPX sends the character e for erase.

Uploading the Code

Now that we have the code for the project, we need to upload it to the CPX.

Let's name our file and download it.

  • Choose a name at the bottom of the page.
  • Then click the pinkDownload button.

Follow the directions and connect your CPX to your computer via the USB cable. Click the CPX Reset button once to go into programming mode (all the Circuit Playground Expresses' LED light NeoPixels will turn green).

In some cases, you may need to press the reset button twice to get into programming mode.

Next, look for the file in your downloads folder and drag it onto yourCPLAYBOOT drive that should have showed up in your file manager/finder when you plugged in your board and entered programming mode.

Once your code file is placed on the CPLAYBOOT drive should  see theCPLAYBOOT drive disappear indicating the code is running.

The code should now be running! Try tilting around the CPX and see if the mouse moves.

Head to our Scratch program, enter full screen and test it out!

  • Tilting the CPX moves around the pen.
  • Clicking button A on the CPX changes colors.
  • Shaking the CPX erases the picture.

Troubleshooting

  • If the pen in scratch is acting glitchy as you tilt the CPX around, try decreasing the value of stepSize.
  • Head here to troubleshoot MakeCode issues.
  • For CPX related issues head here.
  • Head to the Scratch Wiki to troubleshoot Scratch related issues.

What will you create next?

How can you modify what we created to make something even cooler? What other sensors on the CPX could we use to add more effects with the pen in Scratch?

Happy Hacking!

This guide was first published on Jan 18, 2019. It was last updated on Jan 18, 2019.

Can I Buff a Scratch Out of My Drawing Tablet

Source: https://learn.adafruit.com/guide-to-scratch-3?view=all

0 Response to "Can I Buff a Scratch Out of My Drawing Tablet"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel