CSC 110 - Intro. to Computing Lecture 17: Even More Robotran!

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
Pages and boxes Building quick user interfaces. learning objectives o Build a quick UI with pages and boxes o understand how pages and boxes work o click.
CS0004: Introduction to Programming Repetition – Do Loops.
CIS101 Introduction to Computing Week 12. Agenda Your questions Solutions to practice text Final HTML/JavaScript Project Copy and paste assignment JavaScript:
1 Loops. 2 Often we want to execute a block of code multiple times. Something is always different each time through the block. Typically a variable is.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Computer Science 1620 Loops.
Alice Variables Pepper. Set to Java look Edit / preferences restart.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Study Hall: Work on homework, read a book, grab a magazine from the computer table, do something silently. There is no talking. No exceptions.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
Simple Python Loops Sec 9-7 Web Design.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Mini Project II – Drawing Machine
CSC Intro. to Computing Lecture 16: Robotran.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
Fall Week 3 CSCI-141 Scott C. Johnson.  Say we want to draw the following figure ◦ How would we go about doing this?
B.A. (Mahayana Studies) Introduction to Computer Science November March Logo (Part 2) More complex procedures using parameters,
Art 315 Lecture 6 Dr. J. Parker. Variables Variables are one of a few key concepts in programming that must be understood. Many engineering/cs students.
CSC Intro. to Computing Lecture 13: PALGO. Announcements Midterm is in one week  Time to start reviewing  We will do more review in class Tuesday.
Art 321 Lecture 7 Dr. J. Parker. Programming In order to ‘make things happen’ on a computer, you really have to program it. Programming is not hard and.
Introduction to TouchDevelop
Q and A for Chapter 7 Students of CS104, and me, your benevolent professor, Victor T. Norman, PhD.
How to link the robot and the computer (Bluetooth) How to turn on and off How to connect the adaptor Fluke card connection Sec Getting Started How.
CSC 107 – Programming For Science. The Week’s Goal.
CSC 107 – Programming For Science. Announcement Today’s Goal  Know how to write selections besides if-else  Why we use select or if - else and how.
CSC Intro. to Computing Lecture 12: PALGO. Announcements Homework #3 solutions available  Download from Blackboard/web Quiz #3 will be in class.
ENGR 101: Robotics Lecture 4 – Making Decisions Outline  The Stall Sensor  Making Decisions  Random Number Generation References 
I Power Higher Computing Software Development High Level Language Constructs.
JavaScript, Fourth Edition
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
CSC 212 – Data Structures Lecture 2: Primitives, References, & Classes.
1 JavaScript Part 3. Functions Allow the user to decide when a particular script should be run by the browser in stead of running as long as the page.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
CSC 1010 Programming for All Lecture 4 Loops Some material based on material from Marty Stepp, Instructor, University of Washington.
CSC Intro. to Computing Lecture 26: XML & Course Review.
Getting started with the turtle Find the latest version of this document at
Functions.  Assignment #2 is now due on Wednesday, Nov 25 th  (No Quiz)  Go over the midterm  Backtrack and re-cover the question about tracing the.
Event Handling (the right way). A Simple Web Page Events - Summary The web page looks like this:
Beginning C For Engineers Fall 2005 Lecture 3: While loops, For loops, Nested loops, and Multiple Selection Section 2 – 9/14/05 Section 4 – 9/15/05 Bettina.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
BEGINNER FLL PROGRAMMING WORKSHOP BY DROIDS ROBOTICS & EV3LESSONS.
Deriving Consistency from LEGOs What we have learned in 6 years of FLL by Austin and Travis Schuh © 2005 Austin and Travis Schuh, all rights reserved.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
CSC 1010 Programming for All Lecture 5 Functions Some material based on material from Marty Stepp, Instructor, University of Washington.
CprE 185: Intro to Problem Solving (using C)
FLOWCHARTS Part 1.
What you asked me to teach…
© 2015, Mike Murach & Associates, Inc.
More Selections BIS1523 – Lecture 9.
Graph Paper Programming
Graph Paper Programming
Coding Concepts (Sub- Programs)
Alice Variables Pepper.
Algorithm and Ambiguity
Flowcharts and Pseudo Code
Topics Introduction to Repetition Structures
Presentation transcript:

CSC Intro. to Computing Lecture 17: Even More Robotran!

Announcements Quiz #4 will given out at end of class on Thursday  Covers Palgo and Robotran But not Robocop, since I never saw it.   Homework Solutions available on web page Thursday also marks a return to the book  We will be discussing operating systems

Subprograms & Functions & Handlers, Oh My! Often there is code we want to execute repeatedly, but not in a loop  Drawing the sides of a box  Writing each line in the letter “B”  Performing the Open… window  Turning robot around whenever “RUN” button pushed Want to do this without having to rewrite code everywhere.

Subprograms Subprograms begin with a valid name  Any letter combination EXCEPT the program name and reserved words are legal  We will use this, so use a meaningful name drawSquare better than pollyWantACracker Robotran subprograms begin and end similarly: define name The subprogram code goes here end

Simple Subprogram program example1 for s = 1 to 4 do drawLine end define drawLine pen down go forward 1 inch turn sharp right pen up end

More Complex Subprogram What if we want the lines to be different sizes?  Parameters allow us to pass values to a subprogram  Creates new variable(s) at subprogram start and assigns this variable the supplied value  Cannot use the parameters outside the subprogram

Working With Parameters program squares do drawSquare(0.7) go forward 0.1 inch do drawSqare(0.4) define drawSquare(parm length) pen down repeat 4 times go forward length inches turn sharp right end pen up end

Functions Sometimes subprograms should compute a value  Like Excel’s max(), min(), average(), etc.  Subprograms return 1 value at a time  These subprograms called “functions”  This happens a lot in the real world…  …but I lack a good classroom example. Please bear with me!

Function Example program walker var distance var angle while true do let distance = getRand(3) go forward distance inches let angle = getRand(360) turn right angle degrees end define getRand (parm max) returns float var number = random/100.0 * max return number end

Event Handlers Some things in life you can predict:  Death  Taxes  Politicians making impossible promises  People upset at politicians breaking promises  Cubs not winning the World Series For everything else there are Event Handlers™

Robotran Event Handlers These are subroutines that are run only when you hit a button Event handlers cannot use parameters  Remember, cannot be called like subroutines

Button Handler program handler go forward continue when RUN button is pressed var angle = random + 90 turn left angle degrees end when VIEW button is pressed var angle = random + 90 turn right angle degrees end

A Toy My Daughter Would Love program Shoshanna global var count = 0 go forward continue when RUN button is pressed let count = count + 1 stop turn left random degrees end when VIEW button is pressed beep end when PRGM button is pressed display count end

Your Turn Write program so your robot moves forward until it hits something. When it hits something it should stop and beep. Add event handlers so that when the RUN or PRGM button is hit your robot turns around 180 degrees and resumes going forward. Add a global variable which is set to 1 whenever the RUN button is pressed and set to 2 whenever the PRGM button is pressed. Whenever you hit something, display the number of the player who gets a point (e.g., the last player to hit their button) and then turn around and restart going forward.

For Next Lecture Read chapter 10 in the book Study for the Quiz #4