Intro to PicoBoard with Scratch - Library Creation and Learning

advertisement

PicoBoard and Scratch

Introduction to Programming and Physical Computing

Workshop Overview

• Introductions

• The Learning Cycle (STEM  STEAM)

• What is physical computing

• Introduction to Scratch and animating a character

• Connecting to the outside world --

Plugging in the picoboard

• Slider

• Additional resources

The Learning Cycle

Time to play, reflect, question and redesign

General Rules…

Raise your hand if you have a question.

Be respectful.

When I raise my hand…

Share your findings with the people near you.

Poke around, experiment, and have fun…

Imagine, create, and play!!!

About Us

SparkFun Electronics is all about creation, innovation and sharing information. We want to get you excited about cutting edge electronics technology with our hands on educational kits.

What is Physical Computing

Physical computing, in the broadest sense, means building interactive physical systems by the use of software and hardware that can sense and respond to the analog world

-Wikipedia

Resources

This PPT  http://bit.ly/SparkFunPicoScratch001 http://scratched.media.mit.edu/sites/default/fi les/Getting_Started_With_PicoBoards.pdf

http://www.picocricket.com/picoboard.html

What is Scratch?

Scratch is a programming language that makes it easy to create your own interactive stories, animations, games, music, and art -- and share your creations on the web.

Named “Scratch” because it’s embodied after how

DJs re-mix the work of other users. It is intended that users download and remix other users’ projects. Welcome to  Open Source Software http://scratch.mit.edu

Scratch

With the PicoBoard , your Scratch™ projects can sense – and respond to – things going on in the world outside your computer.

Creating your first Animation

Palette – Each of the 8 buttons will show you different functions

Rotation Settings – Control how the sprite rotates:

- rotate freely

- face left \ right Parts of the Screen

Sprite Toolbar –

Duplicate, Delete,

Grow, Shrink

Click & Drag

Scripting Area

Here’s where you build your program – stacking blocks togeteher to create unique functions.

Scratch Exercise 1

Choosing a Sprite and making it move in 4 directions

Choosing your Sprite

(Import from library)

A Sprite is any character or object in your game. Sprites can move and be active or be props that stay still. We will choose a Sprite character that will move about your screen.

• Click on the Costumes Tab

• Click Import

Select a Folder (Animals, People, Things)

• Pick a Sprite! (Double-Click)

Choosing your Sprite

(Camera!)

If your computer has a built-in camera, you can also take a picture of something you’ve drawn or created.

You can use this to create stop-motion animations

(think clay-mation \ Gumby…)

Or… you can use the Paint option window to draw your own sprite

Picking a Background (Stage)

Click on the Stage (lower right)

Click the Backgrounds Tab

Use the Paint / Import /

Camera feature to pick your background.

Making Your Sprite Move

• Sprites can not do anything by themselves. A

Sprite's action comes from the scripts in the script window.

• Scripts are the instructions for exactly what the sprite will do. You drag these instructions from the Tile pane into the "Scripts" pane.

• Tiles fit together like a puzzle to create the instructions.

Event driven instructions

Click the Control button on the scripting palate.

There are 3 different events that you can use to trigger an instruction (code).

Click and drag one of these over to the scripting area.

Making Your Sprite Move…

• Click on the "Motion" button.

• Drag "point in direction

[90]" over to the Scripts window and connect it to the previous command.

• Drag the “move [10] steps" tile and connect it.

• Test it 

Adding animation…

Scratch moves around – but doesn’t look like she’s actually walking.

Click on

Add the next costume block to our script.

Test it 

Play time…

Build an animation to introduce yourself to the class. Choose what key you will use to start.

Play with the various features / programming blocks in scratch.

Here are some examples: http://scratch.mit.edu/projects/2665999/ http://scratch.mit.edu/projects/2001868/ http://scratch.mit.edu/projects/912524/

Back to building simple motion

Save your introduction script.

All files save as *.sb

Start a new file that looks like this 

Adding other controls make your sprite move backwards with another key press.

• Right-click on the code block to copy

(duplicate) what you’ve already done.

• Click the box where it says space and change this to a different key.

Voilla!

You’ve just created “game controls” for your character.

What else can you do?

Plug it in the PicoBoard …

Sensors

Sensor Values

By default, all sensor values vary from 0 to 100.

Use this with Control Blocks to create conditional statements and integrate decision-making.

Light Value

Your sprite can react to light or shade using the data coming from this sensor.

One of the examples in

Scratch uses the light sensor in an interesting animation of the Sun.

Slider Value

This sensor is useful because instead of being a binary sensor, like the button sensor (which turns on or off), this sensor changes continuously on a scale from 0 to

100.

Sound Value

Your sprite can be programmed to react when this sensor detects sound.

For example, a sprite can jump up in surprise if you yell into the sensor, but perhaps not do anything if you simply whisper into the sensor.

Button State (Boolean)

Your sprite can be programmed to react when you push this button.

Make your sprite jump or change colors.

When you stop pushing the button, the sprite will go back to its original state.

Example: Slider Control

Start with the slide potentiometer.

Input Values: 0 – 100

Take these blocks and make this:

Scratch

Scratch rotates from 0 degrees to 100 degrees

How can we use this to get her to rotate a full circle?

Math Lesson:

Rotating a full circle = 360 deg

Rotating a full circle = 360 deg

Using the palette, pull out the divide and the multiply blocks.

Combine these to get the desired formula.

Like this?

Drop this into where you had the angle before

Conditional (Boolean)

Statements

<Boolean statement>

Can be: TRUE or FALSE if (<>)

{

// do something

Assemble these together:

}

Put this all into the forever() loop

Making it better?

Add the pen to Scratch so you can track the path of the animation.

Can you draw out your initials with this?

Can you draw a smiley?

Graphical Effects

•Play around with the different graphical effects under Looks

•Drop the slider control in to add control.

•Remember this needs to be inside the forever()

Building a game.

Step 1: Concept design

Step 2: Storyboarding

Step 3: Prototype / Code

Step 4: User beta testing

Step 5: Presentation

Adding other features

Using the slider to control left-right (x position)

Use the button to

“jump”

Creating a new costume

Click Copy

Click Edit on the new costume (costume3)

Use the Paint Bucket tool to color in Scratch

When the light level gets dark, change costume

What are the light levels in this room?

After you click the checkbox, you should see this  upper left corner

Setting thresholds

Use the Greater Than \ Less Than

Comparison blocks and the if() block to control when your character changes costumes.

Additional Challenges for Today

• Use the slider to control the direction of the character.

• Use the light sensor , program a sprite to hop up and down whenever a shadow passes by.

• Use the slider and button to control a character in a video game.

• Use the sound sensor , you can make a sprite change how it looks whenever there is a loud sound.

• Other ideas???

What else can Scratch do in my class?

Graphing & Data Logging with

Scratch http://bit.ly/18NCuMD

Other Cool animations https://www.dropbox.com/s/ar7gcdoco13vu8

5/Day%20Dream.sb

Questions?

www.sparkfun.com

6175 Longbow Drive, Suite 200

Boulder, Colorado 80301

Download