Global Variables When we introduced variables we defined them inside task main() task main() { int x; statement; …. } The variable x is only defined inside.

Slides:



Advertisements
Similar presentations
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Advertisements

For(int i = 1; i
4.
Lecture 11: Operating System Services. What is an Operating System? An operating system is an event driven program which acts as an interface between.
Object Oriented Programming COP3330 / CGS5409.  C++ Automatics ◦ Copy constructor () ◦ Assignment operator =  Shallow copy vs. Deep copy  DMA Review.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Scratch Programming Session 9 of 10 Review elements to use in stories, games, etc.
NQC: Control Structures: Loops Last updated 10/5/05 References: NQC Tutorial Baum Chapter 3 Baum Appendix D pg 368.
1 Lecture Today’s topic Arrays Reading for this Lecture: –Chaper 11.
Tasks An NQC program consists of at most 10 tasks. Each task has a name. One task must have the name main, and this task will be executed. The other tasks.
RobotC For Beginners Tyler Lutz and Keaton Bonds DRSS Enterprise.
Making a Timer in Alice.
Using the Stop Watch & Scientific Calculator
 Make sure you are subscribed to announcements on Moodle.  Activity 4 will be due 48hrs after your lab ends.
More switches, Comparison Day 7 Computer Programming through Robotics CPST 410 Summer 2009.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Making a Timer in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Wall Encounter By Made easy by Dwayne Abuel.
Basic Operation of a 555 Timer Threshold Control Voltage Trigger Discharge Reset Output.
ITP © Ron Poet Lecture 7 1 Repetition. ITP © Ron Poet Lecture 7 2 Easing Repetitive Tasks  Many computing task are repetitive.  Checking all known foods.
O PERATING S YSTEM. What is an Operating System? An operating system is an event driven program which acts as an interface between a user of a computer,
Lesson 4: Conditional Statements Programming Solutions.
Counting Loops.
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
GCSE Computing: Programming GCSE Programming Remembering Python.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 Functional Abstraction Reduces Complexity.
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Flow of Control: Loops Module 4. Objectives Design a loop Use while, do, and for in a program Use the for-each with enumerations Use assertion checks.
 constant represented by a name, just like a variable, but whose value cannot be changed  The const keyword precedes the type, name, and initialization.
Timer Alarm. What Is The Timer Alarm? The Timer Alarm provides a method for triggering time- based alarms during script playback.
Introduction to Programming in RobotC
INTRODUCTION TO ROBOTICS Part 5: Programming
Store Multiple Results?
Preemption Set timer interrupts But now, must synchronize Two tools:
Python 14 Mr. Husch.
Round Robin Non-Preemptive Scheduler
continued on next slide
Iterations Programming Condition Controlled Loops (WHILE Loop)
                                                                                                                                                                                                                                                
continued on next slide
continued on next slide
Using variables, for..loop and functions to help organize your code
Procedures Programming Guides.
While Loops and If-Else Structures
Functions and Procedures
Lesson 5: Building an App: Clicker Game
The switch statement: an alternative to writing a lot of conditionals
While Loops and If-Else Structures
Arrays .
Module 4 Loops.
Visual Basic: Week 5 Review User defined functions
مديريت موثر جلسات Running a Meeting that Works
امتحانات میں شامل سوالات کے برے ،اچھے اور بہترین نمونے
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
if-else Structures Principles of Engineering
Building a Game in Scratch
IPC144 Introduction to Programming Using C Week 4 – Lesson 1
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops And If-Else Structures
IST256 : Applications Programming for Information Systems
continued on next slide
under the direction of Professor Susan Rodger
while Loops Looping Control Statement
CS100A, Fall 1998 This lecture covers the declaration of variables, assignment, and the if statement. While discussing the declaration of variables,
Scope Rules.
continued on next slide
Presentation transcript:

Global Variables When we introduced variables we defined them inside task main() task main() { int x; statement; …. } The variable x is only defined inside task main. What if we want to use a variable in several tasks?

In the following program the variable bump is known and accessible from all the tasks. int bump=0; task main() { …… } task detect_bump() { …… } task watch_timer() { …… }

A Task That Keeps Track of Time The RCX provides 4 timers which are set to zero when task main() begins running. Each tick of the timer is 0.1sec or 100ms. The time can be accessed by the statement Timer(n); where n=0,1,2,3. A timer can be reset by using ClearTimer(n); Don’t forget that timers work in ticks of 1/10 of a second, while e.g. the wait command uses ticks of 1/100 of a second. #define TIMER_LIMIT 100 task watch_timer() { while(true) { until(Timer(0) > TIMER_LIMIT); PlayTone(440, 10); ClearTimer(0); bumps = 0; }

If I want do something if the number of bumps exceeds some threshold value during a period of time, perhaps 10 seconds, I could use the task from the last slide!