Using the sensor Lesson 5.

Slides:



Advertisements
Similar presentations
Create a Simple Game in Scratch
Advertisements

Create a Simple Game in Scratch
Harry Potter Scratch Game
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Scratch Programming Session 6 of 10 If-then-else statements interactions Final projects specifications.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
INTRODUCTION TO THE SCRATCH PROGRAMMING ENVIRONMENT.
Code Club Session 2 Dance Party. What will we learn ?  How to change the background  How to create animations  How to make objects talk to each other.
We will be creating a spaceship that simulates real movements in space. The spaceship will fire a laser beam that can destroy targets. The spaceship will.
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
Making a Sprite Dance Barb Ericson Georgia Tech June 2011.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Marble Racer. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
Using MIT Scratch for Programming and Control Exercise 1 Creating movement Year 11 DTG 2012.
Programming a Shooter Game Design.
Scratch for Interactivity Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
How to create a basic game in Scratch. The Scratch Stage The Scratch stage is 480 pixels wide and 360 pixels high x increasesx decreases.
Casne.ncl.ac.uk Taking care of the CrumbleBot Please do NOT stress the robot's motors 1.Do NOT push the robot 2.Do NOT hold the.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Scratch Programming Cards
Create a Halloween Computer Game in Scratch
Module 1: Investigation 2 Repeating and Alternating Patterns
Dancing on Green Light.
Scratch for Interactivity
Interacting Sprites Module 3: Investigation 1
Introduction to Scratch
Exploring Mathematical Relationships Module 5: Investigation 3
Building with Numbers Module 4: Investigation 3
Scratch Unit Overview We are going to look at computer programming and how to create your very own computer game The piece of software we will be using.
Module 2: Investigation 1
Unit 2 Getting Started With
Scratch for Interactivity
Gaming with conditionals
Loopy Motion Control.
Learn… Create… Program
Variables Lesson 3.
Getting Started with Scratch
Motion and Looks.
Objective of the lesson
Go to =>
Recap the basics Lesson 1.
Introduction to TouchDevelop
Learning about Conditional Selection
An Introduction to VEX IQ Programming with Modkit
Using the sensor Lesson 5.
Objective of the lesson
Go to =>
Go to =>
Go to =>
Getting Started with Scratch
Put it all together Lesson 5.
Gaming with conditionals
Learning about Conditional Selection before using it inside a Game
I can program behaviours using inputs and outputs
Put it all together Lesson 6.
Getting Started with Scratch
Variables Lesson 3.
Recap the basics Lesson 1.
Learn… Create… Program
I can control a motor and use a sensor
I can program behaviours using inputs and outputs
Obstacle Detection.
Creating a Simple Game in Scratch
Lesson One Movement.
Objective of the lesson
Scratch 7B IT 1.
Presentation transcript:

Using the sensor Lesson 5

What do you think this program will do? Starter What do you think this program will do?

Objective of the lesson Use the distance sensor attached to Edbot All of you will: Use a forever block, if block and the distance sensor to make Edbot react if something is close by. Most of you will: Write a program to help Edbot navigate as it moves around the classroom automatically. Some of you will: Create a program that uses sprites and the distance sensor to control how Edbot moves around the classroom.

Sensor Edbot has a motion sensor at the side of its head. This measures distance and allows Edbot to make a decision based on the data it gets from the sensor. This code will check to see if there is anything within 25cm of the sensor. If there is it will bow and wave. A forever loop will keep repeating the loop until the program is stopped.

If Statements Start Set Edbot to start position Is something within 25 cm of the sensor? No Yes Bow and wave right arm This will check if there is something close by. If there is it will bow and wave its right arm, otherwise it will keep checking until the program is told to stop.

Mathematical Operators In the Operators category there are a number of operators you can use including >, = and <. Open EdbotBlank.sb2 and save it with the name Navigate.sb2. Write a program that will make Edbot walk around the room avoiding the obstacles. Edbot should always try to walk forwards. However, if the sensor picks something up within 20 cm it should walk backwards, pick a random number between 1 and 3 and then repeat a right turn that number of times.

Possible Answer Write a program that will make Edbot walk around the room avoiding the obstacles. Edbot should always try to walk forwards. However, if the sensor picks something up within 20 cm it should walk backwards, pick a random number between 1 and 3 and then repeat a right turn that number of times.

A problem with this program Edbot will try to move forwards. If it spots an obstacle it will move backwards and then turn before moving forwards again. What should happen if there is still an obstacle? Should it still try to walk forwards? We will change this program to use an if…then…else block so that it ONLY moves forward if there is no obstacle in the way.

Compare these two programs Now it will only move forward if there is no obstacle detected. Original code New code

Direct Edbot Open the project called L5_Direct.sb2. There are 4 sprites and a stage to add script to. Add the following script to the correct sprites. Right arrow: when this sprite is clicked turn right. Left arrow: when this sprite is clicked turn left. Up arrow: when this sprite is clicked check to see if the sensor distance is over 20. If it is, walk forwards, otherwise play the “pop” sound. Down arrow: when this sprite is clicked walk backwards. Stage: add a block of script to the stage so that when the green flag is clicked Edbot stands in the initial position. Using your program, see if you can make Edbot walk around a set route. To test the sensor, occasionally put your hand in front of Edbot’s head to see how Edbot reacts.

Self-assessment Read the highlighted points and tick those that you feel you have achieved.