Loops and Switches Pre-Quiz

Similar documents
Loops and Switches Pre-Quiz

What Is a Program? Pre-Quiz

Programming with the NXT using the touch and ultrasonic sensors. To be used with the activity of the How do Human Sensors Work?

Don t Bump into Me! Pre-Quiz

LME Software Block Quick Reference 1. Common Palette

Robotics Study Material School Level 1 Semester 2

Tech Tips. BeeBots. WeDo

Part A: Monitoring the Touch Sensor and Ultrasonic Sensor

Robotics II. Module 5: Creating Custom Made Blocks (My Blocks)

lab A.3: introduction to RoboLab vocabulary materials cc30.03 Brooklyn College, CUNY c 2006 Name: RoboLab communication tower canvas icon

Robolab. Table of Contents. St. Mary s School, Panama. Robotics. Ch. 5: Robolab, by: Ernesto E. Angulo J.

Part A: Monitoring the Rotational Sensors of the Motor

LEGO Mindstorm EV3 Robots

Introduction to Robotics using Lego Mindstorms EV3

INTERMEDIATE PROGRAMMING LESSON

INTERMEDIATE PROGRAMMING LESSON

ROBOLAB Tutorial MAE 1170, Fall 2009

Getting Started Guide

LEGO mindstorm robots

Create a unit using United Streaming and PowerPoint. Materials: Microsoft PowerPoint, Internet access, United Streaming account

Robotics II. Module 2: Application of Data Programming Blocks

the NXT-G programming environment

Module 2, Add on lesson Introduction to the NXT and Mindstorms software. Student. 45 minutes

Robotics II. Module 1: Introduction to Data & Advanced Programming Blocks

Downloaded from

Solving with Seesaws

Module 2, Add on lesson Introduction to the NXT and Mindstorms software. Teacher. 45 minutes

Lab1: Introductory and Setup Activities

EV3 Programming Workshop for FLL Coaches

LEGO MINDSTORMS NXT Lab 4

Worksheet Answer Key: Scanning and Mapping Projects > Mine Mapping > Investigation 2

St Margaret College Secondary School Verdala. Smart Wheelchair. Form 3 NXT Coursework Project. Marquita Formosa (Class X)

EdPy worksheets Student worksheets and activity sheets

How to Use EV3Lessons

Robot Navigation Worksheet 1: Obstacle Navigation

Unit 03 Tutorial 3: Sensors: Touch Sensor Brighton H.S Engineering By: Matthew Jourden

NVTI s POWERPOINT 101

Excel 2013 Intermediate

Robotics II. Module 4: Bluetooth Communication

FACULTY AND STAFF COMPUTER FOOTHILL-DE ANZA. Office Graphics

UNIT 1 مدخالت معالجة مخرجات

Computer Basics: Step-by-Step Guide (Session 2)

ADOBE PREMIERE PRO Lesson: The Basics

Microsoft PowerPoint Presentations

HYPERSTUDIO TOOLS. THE GRAPHIC TOOL Use this tool to select graphics to edit. SPRAY PAINT CAN Scatter lots of tiny dots with this tool.

Introduction: What is NXT-G?

Creative Uses of PowerPoint 2003

Modeling a Gear Standard Tools, Surface Tools Solid Tool View, Trackball, Show-Hide Snaps Window 1-1

PLAY VIDEO. Fences can be any shape from a simple rectangle to a multisided polygon, even a circle.

Using Microsoft Power Point

Working with multimedia

Objective: Combine shapes to create a composite shape; create a new shape from composite shapes.

SketchUp Starting Up The first thing you must do is select a template.

Programmable timer PICAXE programming editor guide Page 1 of 13

Robotics 2c. The Programming Interface

Part II: Creating Visio Drawings

SOLIDWORKS: Lesson III Patterns & Mirrors. UCF Engineering

code-it.co.uk Exploring Regular 2D Shapes & Patterns using sequence, repetition, nested loops, Program Aim: Program regular 2D shapes

Introduction to MS Office Somy Kuriakose Principal Scientist, FRAD, CMFRI

Using StarImpress. A brief introduction

NXT Programming for Beginners Project 9: Automatic Sensor Calibration

Motion Creating Animation with Behaviors

Colin Harman and Jonathan Kim

Introduction to Powerpoint. Create it. Opening a presentation

WIZ-PRO2 CURRICULUM HIGHLIGHTS

INTERMEDIATE PROGRAMMING LESSON

Teacher Cheat Sheet - Game Coding Challenges

Quick guide to connectivity and the ReSound Smart 3D app

Lesson Plan: Refraction of light at boundaries OVERVIEW

Symmetries of Border Patterns

Discovering. Algebra. An Investigative Approach. Condensed Lessons for Make-up Work

-You will need to provide 2 AA batteries and an SD card to use the recorder.

Introduction. Slide Basics. PowerPoint 2010 Slide Basics. Video: Slide Basics in PowerPoint About Slides. Page 1

Microsoft PowerPoint 2013 Beginning

In this lesson you are going to create a drawing program similar to Windows Paint. 1. Start with a new project and remove the default cat sprite.

contents in detail introduction...xxi 1 LEGO and robots: a great combination the EV3 programming environment... 5

INSERVICE DAY - 11/11/11 TECHNOLOGY

Windows Movie Maker lets you edit videos from video and photo files. It is free from Microsoft.

Organize Your iphone: Icons and Folders

PowerPoint Introduction

Create Sponsor Scroll

COPYRIGHTED MATERIAL. Introducing LEGO CHAPTER. Did you get a box that looks like the one shown in Figure 1-1?

I can identify reflections, rotations, and translations. I can graph transformations in the coordinate plane.

Using PowerPoint - 1

2Control NXT FAQ For the latest version of this document please go to > support

USB. Bluetooth. Display. IO connectors. Sound. Main CPU Atmel ARM7 JTAG. IO Processor Atmel AVR JTAG. Introduction to the Lego NXT

On the Web sun.com/aboutsun/comm_invest STAROFFICE 8 DRAW

Lesson 8: Presentation Enhancements Microsoft PowerPoint 2016

Step 2: To begin creating subregions, be sure you still have the Site Floor Plan selected and then click on the Massing and Site tab (1). Under this t

Velocity: A Bat s Eye View of Velocity

The Lego Mindstorms Ev3 Discovery Book Full Color A Beginners Guide To Building And Programming Robots

1-7 Transformations in the Coordinate Plane

Session 7 MS Word. Graphics. Inserting Clipart, and Graphics Modify graphics Position graphics

Civil Engineering Computation

TSS. Event CAD Tutorial. Event Hire Software. Software Solutions for the Event Hire Industry. 2D/3D Layout and Presentation. T S Solutions Limited

What you can do: Use Transparency #10

Presents: PowerPoint 101. Adapted from the Texas State Library s TEAL for All Texans Student Resources Manual

BEGINNER PROGRAMMING LESSON

EEL 5666C FALL Robot Name: DogBot. Author: Valerie Serluco. Date: December 08, Instructor(s): Dr. Arroyo. Dr. Schwartz. TA(s): Andrew Gray

MICROSOFT POWERPOINT 2016 Quick Reference Guide

Transcription:

Loops and Switches

Loops and Switches Pre-Quiz 1. What kind of blocks are these? 2. Name two kinds of controls that can be specified to determine how long a loop repeats. 3. Give an example of a program you could write that would use a switch. 2

Loops and Switches Pre-Quiz Answers 1. What kind of blocks are these? loop switch 2. Name two kinds of controls that can be specified to determine how long a loop repeats. Any two of these: Forever (a never-ending loop), any sensor, count (tell the loop to repeat, for example, 5 times), time (tell the loop to repeat, for example, 1 minute), logic 3. Give an example of a program you could write that would use a switch. Example answer: While the touch sensor is pressed, go forward; otherwise, move backwards. 3

What are loops and switches? Objective Loops and switches are two of the most important tools used in programming. Loops allow us to repeat segments of a program indefinitely or until some condition is met Switches allow a program to respond differently to different conditions In today s lesson, we: Investigate how loops and switches work (50 minutes) Learn how to use loops and switches when we program using the LEGO MINDSTORMS NXT software Learn to use switches and loops in unison to expand the functions 4 of the programs we will make

Loops: What Are They? o In programming, a loop is an operator that allows us to repeat a set of commands indefinitely. o In many factories, a machine performs the same simple task thousands of times in a day o Watch a video clip of an assembly machine www.youtube.com/watch?v=awjflkd6y_o (1:41 minutes) o As a programmer, you don t want to have to copy instructions for repeating that same simple task thousands of times o So, instead, you write commands for the simple task 5 once, and then enclose those commands in a loop, which can be repeated as many times as you want.

Programming with Loops Suppose we want to make a robot move once around in a square. start/stop at this corner A program to do that has 8 blocks and would look like this: 6

Programming with Loops (continued) Programming this task becomes a lot easier if you use loops. Notice that the 8 commands we would use to do this (forward, right, forward, right, forward, right, forward, right) are really just the same 2 commands repeated 4 times So. what we really want to program is simply: Repeat (1. go forward; 2. turn right) 4 times. In the LEGOMINDSTORMS NXT software, the loop block icon looks like this Drag this block down to the main line of your program as shown: 7

Programming with Loops (continued) When you highlight the loop block, notice the dropdown menu next to Control. The Control options enable you to tell a robot how long to keep looping the commands inside the loop. Selecting Forever repeats those commands indefinitely. Selecting Sensor repeats those commands until a sensor detects a stimulus (for example, until the touch sensor is pressed). Selecting Time repeats those commands until a certain amount of time has expired (for example, 5 minutes). 8

Programming with Loops (continued) Selecting Count repeats those commands some specific number of times. We won t discuss selecting Logic at this time, because it is a bit too complicated for our application. In this case, what do we choose? Since we want the commands (go forward, turn right) to be repeated 4 times, we select Count and set count to 4. 9

Programming with Loops (continued) Next, we need to drag the commands we want to be repeated INSIDE the loop. The final program looks like this: Notice that instead of 8 blocks, we only need 2 blocks, surrounded by a loop. 10

Mini-Activity 1 Do This: Fill out Part 2 of the worksheet. Then program the robot to: Go forward until it hits a wall, then back up one rotation and turn left Repeat these instructions until detecting a sound Then stop 11

Mini-Activity 1 Programming Solution 1 2 3 12

(continued) Mini-Activity 1 Programming Solution 4 5 6 13

Day 2: What Is a Switch? In programming, a switch is an object that gives different commands depending on which state it is in. A light switch for example, has 2 states: up and down. When the light switch is in the up position, the switch directs the light it controls to turn on. When the light switch is in the down position, the switch directs the light it controls to turn off. 14

Programming with Switches Suppose we want to program a robot to end up exactly 24 inches from a wall no matter where it starts. This means that the robot will always be in one of two states: 1. closer than 24 inches to the wall or 2. farther than 24 inches from the wall We can best deal with this situation by using a switch. To do this, click on the switch icon: and drag it down to the program line. 15

Programming with Switches (continued) When you highlight the switch block, notice that you can indicate the sensor used. In this case, we are interested in how far away the robot is from the wall, so we select the ultrasonic sensor from the drop-down menu. Because we want the state of the switch to depend on the distance the robot is initially away from the wall, we also need to set the distance to 24 inches. 16

Programming with Switches (continued) If the condition specified is satisfied, the program will execute the commands in the top half of the switch. This means the robot is less than 24 inches from the wall and we need the robot to back up until it is at least 24 inches away from the wall. We can achieve this by using a backward move block with unlimited duration followed by a wait block as shown below. 17

Programming with Switches (continued) If the condition specified is not satisfied, the program will execute the commands in the bottom half of the switch. This means the robot is more than 24 inches from the wall and we need the robot to go forward until it is closer than 24 inches from the wall. We can achieve this by using a forward move block with unlimited duration followed by a wait block as shown below. 18

Mini-Activity 2 Do This: In worksheet Part 3, write out the program we just discussed in WORDS, that is, as an algorithm, and understand it fully. Then, write the NXT program, download it onto the LEGO taskbot and verify that it works correctly. Note that all the blocks for this program are provided on the previous slides. 19

Mini-Activity 2 Programming Solution 20

Mini-Activity 3 Do This: Program the robot so that: It moves forward until it hears a sound. If the touch sensor is pressed when it hears a sound, turn left. If the touch sensor is not pressed when it hears a sound, turn right. 21

Programming Activity Solution 1 2 3 22

Programming Activity Solution (continued) 4 5 23

Loops and Switches Post-Quiz 1. What kind of blocks are these? 2. Name two kinds of controls that can be specified to determine how long a loop repeats. 3. Give an example of a program you could 24

Loops and Switches Post-Quiz Answers 1. What kind of blocks are these? loop switch 2. Name two kinds of controls that can be specified to determine how long a loop repeats. Any two of these: Forever (a never-ending loop), any sensor, count (tell the loop to repeat, for example, 5 times), time (tell the loop to repeat, for example, 1 minute), logic 3. Give an example of a program you could write that would use a switch. Example answer: While the touch sensor is pressed, go forward otherwise move backwards. 25

Vocabulary loop: A command or operator that repeats a set of commands. switch: In programming, an object that gives different commands depending on which state it is in. 26

Images Sources Slide 1: girl on floor with laptop; source: Microsoft clipart: http://office.microsoft.com/enus/images/results.aspx?qu=laptop&ex=1#ai:mp900442369 Slide 1: multicolored chevron loop; source: Microsoft clipart: http://office.microsoft.com/enus/images/results.aspx?qu=cycle&ex=1#ai:mc910216324 Slides 1, 14: wall switch drawing; source: Microsoft clipart: http://office.microsoft.com/enus/images/results.aspx?qu=light+switch&ex=1#ai:mc900441745 Device and programming images from LEGO MINDSTORM NXT User s Guide http://goo.gl/wuhsua Screen captures and diagrams by author 27