Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.

Slides:



Advertisements
Similar presentations
Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
Advertisements

While Loops and If-Else Structures
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
Team 5220 Roboknights. Outline  Getting Started  Hardware Setup/Wiring  Software Setup/Pragmas  Programming with RobotC  Grammar/Syntax  Basic Statements.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Chapter 2: Introduction to C++.
Introduction to Sensors
Section 2 - More Basics. The char Data Type Data type of a single character Example char letter; letter = 'C';
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Input & Output: Console
 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CPS120: Introduction to Computer Science
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
1 C++ Syntax and Semantics, and the Program Development Process.
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
Fundamental Programming: Fundamental Programming Introduction to C++
ROBOTC for VEX Online Professional Development. Warm-up Activity Review/Watch videos from VCVT –Especially the ones from the Fundamentals and Movement.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
Variables in Java x = 3;. What is a variable?  A variable is a placeholder in memory used by programmers to store information for a certain amount of.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
While and If-Else Loops ROBOTC Software. While Loops While loop is a structure within ROBOTC Allows a section of code to be repeated as long as a certain.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
ROBOTC for VEX Online Professional Development. Homework Questions Thoughts? Questions? Concerns? Homework Policy: All homework is due Friday, August.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
ROBOTC for VEX Online Professional Development Jesse Flot.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Variables. A variable is a space in your robot’s memory where you can store data, such as whole numbers, decimal numbers, and words. Variable names follow.
Bill Tucker Austin Community College COSC 1315
Introduction to Programming in RobotC
Variables and Functions
Chapter 2: Introduction to C++
Variables and Functions
Variables and Functions
ROBOTC for VEX Online Professional Development
Variables and Functions
Using Encoders to go Straight
Chapter 2: Introduction to C++
Time Manager Class Activity Material Manager Writer leader Communicator Programmer Start a journey from the capital AbuDhabi to Alasmaa School using your.
Variables and Functions
Variables and Functions
Variables and Functions
Variables and Functions
Using variables, for..loop and functions to help organize your code
2.1 Parts of a C++ Program.
Variables and Functions
Auto Straightening using VEX Shaft Encoders
C++ Data Types Data Type
Multitasking Emergency Stop Computer Integrated Manufacturing
if-else Structures Principles of Engineering
Chapter 2: Introduction to C++.
Robotics Programming Using Shaft Encoders
Variables and Constants
Presentation transcript:

Variables and Functions ROBOTC Software

Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal numbers, and words Variable names follow the same rules as custom motor and sensor names: capitalization, spelling, availability Variables can improve the readability and expandability of your programs

Variable Types Data TypeDescriptionExampleCode IntegerPositive and negative whole numbers, as well as zero -35, -1, 0, 33, 100 int Floating Point Number Numeric values with decimal points (even if the decimal part is zero) -.123, 0.56, 3.0, float BooleanTrue or false – Useful for expressing the outcomes of comparisons true, false bool CharacterIndividual characters, placed in single quotes ‘L’, ‘f’, ‘8’ char StringStrings of characters, such as words and sentences placed in double quotes “Hello World!”, “asdf” string

Creating a Variable To create a variable, you must give it a: 1.Type: Data type it will hold 2.Name: How variable can be referenced Variables can be set to different values throughout program Giving a variable an initial value is called “initializing the variable”

Global vs. Local Variables Variables can be considered either “global” or “local”. –Global variable Can be read or changed from any task or function in your code. Its value can be seen/read globally. –Local variable belongs to the task or function in which it was created Value can only be read or changed from within that task or function Value can only be seen/read locally Generally the type of variable you’ll want to use

Creating Local Variables (preferred) To create a local variable, declare it within the curly braces of task main or one of your functions. You will only be able to change the value of this variable within its task or function.

Creating Global Variables To create a global variable, declare it after your pragma statements, but before task main or any function declarations. This will allow your variable to be changed by any task or function in your program.

Functions –Group together several lines of code –Referenced many times in task main or in other functions Creating Functions Example: LED on if bumper is pressed, off if released 1.Function header (name of function) 2.Function definition (code in the function) 3.Function call (where function code will run)

Sample Function “LEDControl()”

Function Declaration Function declarations (or prototypes) declare that a function exists and indicates its name Function declarations between #pragma statements and task main Function declaration optional if function definition is above task main

Function Definition Function definitions define the code that belongs to the function

Function Call Function calls –Call and run code from function –Placed in task main or other functions

References Carnegie Mellon Robotics Academy. (2011). ROBOTC. Retrieved from