If you note any errors, typos, etc. with this manual or our software libraries, let us know at
|
|
- Neal Ferdinand Cummings
- 5 years ago
- Views:
Transcription
1 Oregon State University Robotics Club ORK 2011 Programming Guide Version 1.0 Updated: 10/28/2011 Note: Check back for more revisions and updates soon! If you note any errors, typos, etc. with this manual or our software libraries, let us know at Necessary Software The following software and code will need to be downloaded to program your ORK. The programs or links to get them are available on the ORK Website. WinAVR - or - avr-gcc, avr-binutils, avr-libc ORKWare Loader Application Java Runtime Environment A text editor of your choice for writing the code, Notepad++ or Programmer s Notepad are good text Editors for Windows. Also, download the starter code (ORKWare.zip) 1. Getting started with C Syntax and Basics Before writing a program in C for the ORK, you should read over the first part of this manual and some of the code in the ORKWare libraries in ORK_lib.zip. C has a specific syntax (the way the code has to be typed) and has many basic rules, commands, structures, and operators that are the building blocks of any program you will write. If you have programmed before in C, then this first section should mostly be review and can be skipped. Case sensitivity C is case sensitive, so everything written in code needs to be correctly typed otherwise the code cannot be compiled into a program. Be very aware of this when you are writing your code, it will save you time in the long run. Brackets, braces, and parentheses Any time an opening (left) parentheses, brace, or bracket is created, a right handed parentheses, brace, or bracket must be properly nested so the last open brace is the next one that is closed. Having a ( followed by a ] will prevent your code from working as a program. In general, if a bracket, brace, or parentheses is missing or out of place, your program will not compile. It is often a good practice to create open and closing punctuation in your code at the same time before writing what goes inside of them. Page 1 of 14
2 Example of proper bracket, brace, and parentheses use int function(char parameter1) if(a==b) array[b]=z++; //Notice the balanced braces? Line endings The end of each statement must have a semicolon typed at the end of the line. Some lines, such as ones with if, else, or most loop statements do not need a semicolon after the statement. If you do not add these semicolons, the program will not compile and cite missing semicolons as the cause. For example: int a = b+2; //Note the semicolon Numbers When you write in C, you can express numbers in three different bases: binary (0 or 1), decimal (0-9), and hexadecimal (0-F, really 0-15). In some cases, in most higher level programs, decimal values are typically used, however in some cases with low-level programming, it may be easier to write numbers in binary or hexadecimal. Decimal values can simply be written into your code as is. To write a binary number, type 0bNUMBER before the value or to write a hexadecimal (hex for short) value, type 0xNUMBER. Examples of 47 in binary, decimal, and hexadecimal: Binary: 0b Decimal: 47 Hexadecimal: 0x2F Logical Values You may be familiar with simple Boolean logic, possibly from other languages, where there are explicit True and False values in the language to handle logical statements, such as (4 greater than 3), which would be true. In C, logical values, which should make more sense in the examples, take on the values of any number that is 0 for False and any non-0 number for True. It is possible to define the words true and false as 1 and 0. Operators In C there are a number of simple arithmetic operations that you should be familiar with as well as Boolean logic and bitwise logic operators. Operators simply manipulate data, for example xadding two numbers or checking whether Page 2 of 14
3 multiple conditions are true at the same time. Become acquainted with what these operators mean as most C statements typically include multiple operators. Arithmetic Operators Most of the ones that you will need are listed here. The assign = stores a value into a variable, the four basic math operators, +,-,*, and / operators perform addition, subtraction, multiplication, and division, and the increments and decrements add or subtract one from a value. Table of Arithmetic Operators Operation How to code it What it does Assign a = b Stores b in a Add a+b Adds a and b Subtract a - b Subtracts b from a Multiply a * b Multiplies a times b Divide a / b Divides a over b Increment a++ or ++a Adds one to a Decrement a-- or --a Subtracts one from a Logical Operators Logical operators perform simple Boolean operations to the logical values of numbers in C. They are useful for evaluating multiple logical statements at once to make compound logic. For example using an if statement, IF NOT A AND NOT B are both true then do some other activity. Table of Logical Operators Operation How to code it What it does Equate a == b Checks if a is equal to b, do not use a=b for this NOT!a Inverts the logical value of a AND a && b Returns true if both a and b are true, otherwise false OR a b Returns true if a or b, or both, are true, otherwise false Bitwise Operators Bitwise operators perform numerous logical functions on the individual bits of a number. Every number is stored as a binary value on the microcontroller, and each one of these operations goes through and performs the following operation on each one of the digits of that binary number. Table of Bitwise Operators Operation How to code it What it does NOT ~a Inverts each bit of a: AND a & b ANDs each bit of a and b: 1001 & OR a b ORs each bit of a and b: XOR a ^ b Exclusive ORs each bit of a and b: 1001^ Left Shift a << b Shifts the bits of a left by b: 00101<< Right Shift a >> b Shifts the bits of a right by b 10100>> Page 3 of 14
4 Data Types and Variables Variables Data in C is entered in what are called variables. Variables have a data type, a name, and a value. To create a variable, you must declare what type it is and give it a name. To assign a variable a value such as a constant number, or another number, use the = operator. Example variable declaration and initialization. int a; a=3; char z = 33; Integer Types: char, int, long Each of these types stores an integer with a different number of bytes with char being the shortest, up to long being the longest in general use. These values have different ranges of values as some take up more space in memory, and more processing power to handle than others. The data type must be large enough to hold the largest number you expect to hold in that variable. The range of acceptable values for each type. Basic integer types, sizes, and their range of values. char (1 byte): -128 to 127 int (2 bytes): -32,768 to 32,767 long (4 bytes): -2,147,483,648 to 2,147,483,647 Signed and Unsigned numbers Numbers may also have a sign, meaning it can be positive or negative, or be unsigned and strictly positive. Any integer declared just using the above types will automatically be signed. The advantage of using unsigned numbers is that it increases the positive range of values by a factor of 2. So an unsigned char goes from 0 to 255 instead of -128 to 127. For many things, like counters, distance sensor values, or anything else that would only have a positive value, an unsigned number would be the best way to store it. Numbers that can be positive or negative, say the motor velocity, should be stored to signed numbers. Floating Point Numbers (i.e. numbers with a decimal point) Most microcontrollers, the ATMega32 included, do not have hardware capable of easily doing basic arithmetic with non-integer numbers like 42.3 or You may use the types float or double in your code, which will compile and work, however it takes the processor significantly longer to calculate with these numbers and may slow your program down noticeably. Page 4 of 14
5 Functions What is a function? A function is a reusable piece of a program that takes some input and subsequently produces some output depending on the inputs it has received. How to write a function Each function needs five things, a return type, a function name, parameters, the actual code to execute in the function, and a return statement. The code to execute is written to do what you want the function to do, however the following function components are necessary to know in order to implement functions. Return Type: Each function requires a return type to be declared at the very start of the function. If it returns an int, then you would write int functionname. Functions may return nothing, in which case the type void is used. Often times if you just want to change something but do not need a value back, void functions should be used. Function Name: Each function requires a one word function name, which is usually written starting with a lower case number. You can only have one function per function name, and it cannot conflict with any statement in C, so you can t have a while() function for example. Parameters: Parameters, the inputs of a function that go in parentheses and each one must have a type assigned to it, such as int, char, etc. These can be referred to in your function by the name given to them in the function header. Return Statements: All non-void functions require you to return a value at some point in the function. This is done with a return statement. To return from a function, type return and then the value (a number or a variable) to return after it. This exits the function and allows you to have the value in the part of your program where the function was called. returntype functionname(type param1, type param2) //Write code in here for function return value; The main() function Every program in C must have at least one function, the main() function. It is included in the starter code with a type of int. The main() function encapsulates the entire program, so when it starts, it starts in the main function and ends when the main function is finished (something you usually don t want to experience with your ORK). Page 5 of 14
6 How to call a function in your program To call any function in your program, simply type the function name followed by values for each parameter in parentheses separated by commas. To store the return value of a function, simply assign it to a variable. An example is shown below: Example of calling myfunction with parameters 1, 2 and storing the result to a int myfunction(int p1, char p2) int main() int a = myfunction(1,2); return 0; Flow Control When writing programs in almost any language, you will often find it necessary to control how the code you write is executed. Rarely is a program written that simply executes all of its instructions in order without regard to inputs or conditions within the program. Thus you will need to become acquainted with what are called flow control statements to allow your program to choose to execute certain pieces of code, for example moving forward only if one of the line sensors detects the line. If statements If statements in C allow you to control whether or not the block of code following it is executed depending on some condition being true. The basic syntax is shown below, where condition is some logical condition such as two numbers being equal, a value not being zero, or something else that can be answered with true or false. If that condition is true, then the next block of code in curly braces, or the next line, is executed. If the condition is false, then the program simply skips that portion of the code. if(condition) // execute this code if condition is true Else statements Another useful statement is the else statement. After the end of any block of code in an if statement, an else statement can be evaluated. If the condition of the if statement is false, then the code in the else block is executed, so the program has to choose one or the other based on condition. Page 6 of 14
7 Example if-else block if(condition) // code to execute if condition is true else // code to execute if condition is false Loops In most programs from robots up to desktop applications, there are frequently tasks that need to be repeated numerous times, sometimes indefinitely. Instead of simply writing the same code over and over to do this until you run out of program space, the C language has built in loops that will execute a block of code repeatedly. The three types of loops in C will be discussed briefly below. While Loops While loops are one of the easiest types of loop to understand, and you will frequently use them in your programs. A while loop simply continues executing a block of code as long as a condition is logically true. This condition is only checked once per loop cycle at the start of the loop, so the code in the braces will execute up through the last cycle where condition is true. The basic syntax of a while loop and a quick example follow: while(condition) Code to execute goes here Example while loop that adds one to z until z=4 int z=2; while(z!=4) z=z+1; Do-While Loops Do-While loops are similar to while loops, however they check the loop condition at the end of the loop cycle instead of the start. The syntax of a do-while loop is as follows: do Code to execute goes here while(condition); Page 7 of 14
8 For loops For loops are used to execute a block of code for some number of iterations. If you need to do something 10 times or count through some number of values, such as the elements in an array, a FOR loop is most commonly used. A for loop requires a counter variable, some logical condition to check to stay in the loop and something to do to the counter variable in each loop cycle. The basic syntax and an example follow: declare counter variable for(initialize counter; condition to exit loop; action to take each loop) Code to execute goes here Example FOR loop that runs 10 times (i=0-9, incrementing once per loop) multiplying the value z by 2 each iteration. The result of z should be z*2 10 : int z=1; unsigned char i; for(i=0, i<10 ; i++) z=2*z; Comments Comments are parts of a program source code file that are written so programmers can document their code and understand other people s code as it is not always 100% readable. When code is compiled into a program, the computer skips over all commented areas so portions of code can even be turned into a comment. There are two ways to make comments in C, which will be briefly described. Single line comments start with // and continue to the end of the current line. Multi line comments allow you to comment out multiple lines of a file starting with /* and ending with the opposite */. Both types of comment can be used to comment out parts of your code if you wish to temporarily disable it. Commenting Examples: // This is a single line comment comment /* This is * a * multi line comment */ // a = b+c; Headers, Source Files, and Libraries Often times when writing in C, you will not want to write every program entirely from scratch in one.c file. Thankfully, C allows for code reuse and use of multiple code sources with #include statements. The #include statement allows you to use what are known as header or.h files, which Page 8 of 14
9 include programming definitions, function declarations, and other important information about another.c file or a pre-compiled library containing the implementation of that information. Effectively it allows you to have a functions and data in another file that can be called from the file you are currently working in. Including header files is done in one of two ways. First, if the header is from a standard library for AVR-GCC, such as the I/O library, the delay library, or the default AVR serial libraries, then the file name to include goes in angle brackets < and >. These standard libraries come with Win- AVR and AVR-GCC should automatically know where to find them. If you want to include another one of your source files, or one from the ORKWare library source, the file name relative to the main project folder must be entered using quotations and. For example if you are working in the ORKWare folder, the relative file name for the motor library would be OrkLib/OrkMotorBasic.h Example of including header files: //Include a standard library with <header.h> #include <avr/io.h> //Include your own source file with header.h #include OrkLib/OrkCore.h 2. Writing a Simple ORK Program Now with a basic understanding of how to program in C, let s write a simple program for the ORK to get used to the libraries created for making the ORK move and sense things in its environment. Using a text editor (Programmer s Notepad for example) open the file OrkMain.c that was included in ORKWare.zip. You should scroll down to the main() function to begin writing your program. This code makes the ORK perform a slow dance of moving forwards, backwards, and then turning left before repeating the process. The program only requires two functions from the ORKWare libraries, setmotor(motoraddress, speed) and delay(time). The delay function simply makes the robot continue doing what it is currently doing for the number of milliseconds entered into the parameter. The set motor address sets the speed of each motor with two parameters, the motoraddress to which you should enter LeftMotor or RightMotor and a speed from -128 to 127. The speed is full forward at 127, stopped at 0, and full reverse at Now, write the following code inside the curly braces in the while(1) loop located in the main function. Page 9 of 14
10 int main() while(1) // Start your program here // Go Forwards setmotor(leftmotor,127); setmotor(rightmotor,127); delay(1000); // Delay for 1000 milliseconds // Go Backwards setmotor(leftmotor,-128); setmotor(rightmotor,-128); delay(1000); // Turn Left setmotor(leftmotor,-128); setmotor(rightmotor,127); delay(1000); // End your program here Now compile your code using the included makefile. To do this in programmer s notepad go to Tools->[Win-AVR] Make All and AVR-GCC should begin running. Text should start appearing in the output console at the bottom of the screen and eventually it will say in blue letters that the exit code is 0. If the exit code is not 0, there were errors with the program that will be described further up in the output console. You should now have a file called orkprogram.hex in the source folder, this contains the program that is ready to be loaded onto the ORK. 3. Loading a Program onto the ORK over USB Connecting the ORK to a PC 1. Set the RUN/PRG jumper to the PRG position 2. Power on the ORK 3. Press the red reset button, the LED labeled LED should turn on 4. Plug the ORK into the PC with a USB A to mini-b cable 5. The ORK should now be connected Using the ORKWare USB Loader: 1. Open ORKWare Loader.jar 2. Check that the selected microcontroller is an ATmega32U4 3. Click the Browse button and find 4. Click the Program button to load your program onto the ORK 5. Wait until the output console says that programming has completed successfully 6. Set the ORK RUN/PRG jumper to the RUN position 7. Reset the ORK with the power jumper or reset button Page 10 of 14
11 4. Making Your ORK Follow a Line Basics of Line Following Basics of the Challenge The goal of the line following challenge will to have your ORK, or any autonomous robot, navigate across a black electrical tape curve on white paper from a starting point to an ending point. The line will have multiple changes of direction, right angle turns, and may have gaps from 1-2 in the line. The robot that makes it to the end the fastest, over multiple trials, wins the competition. Any close times will result in a sudden death match. The end will be marked by a solid black square the size of the robot. In general, the closer you stay to the line, the less distance you must travel and the quicker you make it to the end. Try to optimize your robot so that it does not wobble much on the line. Hardware modifications may give you a serious edge, including higher power motors and motor drivers that will increase the speed of your robot. Controlling Motors To control the motors, use the setmotor(motor, speed) function from the OrkMotorBasic.h file. This function sets the specified motor to some speed between -128 to 127. The motors are already defined in OrkMotorBasic so you may simply type LeftMotor or RightMotor into this function to address the motor correctly. Enter a char value in as the speed parameter, keeping in mind that positive values make the motors go forwards, zero is stopped, and negative values go backwards. Once the motors are set to a speed, they will continue to operate at that speed until it is updated by another setmotor() call. For very low speeds, the motors may not turn as they require some minimum power to overcome friction. Example for making the robot spin to the right slowly: setmotor(leftmotor, 80); setmotor(rightmotor, -80); Reading Sensors The line sensors work by reflecting infrared (IR) light off of a nearby surface into an IR detector. If the surface is highly reflective, as white paper is, then the sensor will return a 0 or False value. If the sensor is above a non-reflective surface, such as a black line, then they will return a 1 or True value. To read in these sensors, you will have to read the digital input of the microcontroller that is connected to each sensor. To do this, use the readdigitalpin(address) function. This function returns the logical value (0 or 1) of the sensor input at the address. For the address input, use CON1, CON2, CON3, etc. for the sensor hooked up to that connector. Page 11 of 14
12 Example for reading a line sensor. The returned value of the function can also be used as a truth value and be evaluated with other sensor values as shown in the if statement. unsigned char sensor1; sensor1=readdigitalpin(con1); if(readdigitalpin(con2) && readdigitalpin(con3)) //Do something here Handling Input Much of your line following program will likely be if and else statements that check the values of the sensors and then act on each sensor combination. Prior to coding, the best thing to do will to write down all of the possible sensor combinations you wish to handle, write down what each set of sensor inputs means, and write down what you think the robot should do in each case. This can then be turned into a large series of if-else statements to check each one of your states. You don t need every single sensor combination in the if statements, just the ones that cause the robot to change what it is doing. You can also simplify the states if you do not care about some of the sensors for a particular set of states (for example only needing the input from the center two sensors) Example using if-else statements to check robot states and act on them bool sens1, sens2, sens3, sens4; while(1) sens1=readdigitalpin(con1); sens2=readdigitalpin(con2); sens3=readdigitalpin(con3); sens4=readdigitalpin(con4); // All sensors detect a line At the end if(sens1 && sens2 && sens3 && sens4) // Stop setmotor(leftmotor, 0); setmotor(rightmotor, 0); else // All but sensor 4 detect the line if(sens1 && sens2 && sens3 &&!sens4) Page 12 of 14
13 else // Swing to the left setmotor(leftmotor, 0); setmotor(rightmotor, 127); Using Delay One useful tool in making a simple line follower is the use of time delays. As most of your program will likely execute thousands up to hundreds of thousands of times per second, this can sometimes lead to updates that are too fast to even have a noticeable effect on the physical robot system (such as changing the motor speed). Slowing your program down so it only changes its motor speed around times per second will mostly fix this problem. To do this, add a delay by using the delay() function. The parameter of the delay is simply the time to wait in milliseconds before going to the next line of code. Example of using a delay at the end of a loop while(1) delay(20); // Delay for 20ms 5. Debugging Your Code Coming Soon Appendix A: ORK Library Reference OrkCore Definitions TRUE and true, 1 FALSE and false, 0 CON1, 1 CON2, 2 CON3, 3 CON4, 4 CON5, 5 CON6, 6 CON7, 7 Types char Boolean unsigned char unsigned 8-bit integer: uint8 Functions bool readdigitalpin(unsigned char address) Reads the digital value (0 or 1) of the addressed pin Page 13 of 14
14 Valid inputs: CON1-CON7 Output: The value (0 or 1) returned by the sensor plugged into the CONx sensor bool readlinesensor(unsigned char address) Currently the same as readdigitalpin() Valid inputs: CON1-CON7 Output: The value (0 or 1) returned by the sensor plugged into the CONx sensor bool readproxsensor(unsigned char address) Currently the same as readdigitalpin() Valid inputs: CON1-CON7 Output: The value (0 or 1) returned by the sensor plugged into the CONx sensor void ledon() Turns the LED on void ledoff() Turns the LED off void ledtoggle() Toggles the LED on and off OrkMotorBasic Coming Soon OrkMotorL298 Coming Soon OrkADC Coming Soon Appendix B: Advanced AVR Programming Topics The basics of AVR I/O ADC Usage Timer/Counters and PWM Serial Communications Glossary -Under Construction- Page 14 of 14
C Programming with Mini Sumo Robots
C Programming with Mini Sumo Robots Editing and Compiling a Program -Open Programmer s Notepad. This will bring up a tool for editing and compiling your program: -Start Menu -> Programmers Notepad -> Programmers
More informationArduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.
Introductory Medical Device Prototyping Arduino Part 1, http://saliterman.umn.edu/ Department of Biomedical Engineering, University of Minnesota Arduino Uno Power & Interface Reset Button USB Interface
More informationME 461 C review Session Fall 2009 S. Keres
ME 461 C review Session Fall 2009 S. Keres DISCLAIMER: These notes are in no way intended to be a complete reference for the C programming material you will need for the class. They are intended to help
More informationC Language Programming
Experiment 2 C Language Programming During the infancy years of microprocessor based systems, programs were developed using assemblers and fused into the EPROMs. There used to be no mechanism to find what
More informationBasic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition
Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationGeneral Syntax. Operators. Variables. Arithmetic. Comparison. Assignment. Boolean. Types. Syntax int i; float j = 1.35; int k = (int) j;
General Syntax Statements are the basic building block of any C program. They can assign a value to a variable, or make a comparison, or make a function call. They must be terminated by a semicolon. Every
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationCreating a C++ Program
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an
More informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More informationThe C Programming Language Guide for the Robot Course work Module
The C Programming Language Guide for the Robot Course work Module Eric Peasley 2018 v6.4 1 2 Table of Contents Variables...5 Assignments...6 Entering Numbers...6 Operators...7 Arithmetic Operators...7
More informationComputer Programming : C++
The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program
More informationChapter 2: Using Data
Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time
More informationObjectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments
Basics Objectives Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments 2 Class Keyword class used to define new type specify
More informationIntroduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur
Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture - 23 Introduction to Arduino- II Hi. Now, we will continue
More informationJava provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:
JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
More informationIntroduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands
Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationMr. Monroe s Guide to Mastering Java Syntax
Mr. Monroe s Guide to Mastering Java Syntax Getting Started with Java 1. Download and install the official JDK (Java Development Kit). 2. Download an IDE (Integrated Development Environment), like BlueJ.
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationBASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I
BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment
More informationG. Tardiani RoboCup Rescue. EV3 Workshop Part 1 Introduction to RobotC
RoboCup Rescue EV3 Workshop Part 1 Introduction to RobotC Why use RobotC? RobotC is a more traditional text based programming language The more compact coding editor allows for large programs to be easily
More informationOperators. Java operators are classified into three categories:
Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.
More informationExpressions and Data Types CSC 121 Fall 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationThe Arduino Briefing. The Arduino Briefing
Mr. Yee Choon Seng Email : csyee@simtech.a-star.edu.sg Design Project resources http://guppy.mpe.nus.edu.sg/me3design.html One-Stop robotics shop A-Main Objectives Pte Ltd, Block 1 Rochor Road, #02-608,
More informationThese are notes for the third lecture; if statements and loops.
These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern
More informationDEPARTMENT OF MATHS, MJ COLLEGE
T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,
More informationA flow chart is a graphical or symbolic representation of a process.
Q1. Define Algorithm with example? Answer:- A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of
More informationControl Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003
Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an
More informationC++ Reference NYU Digital Electronics Lab Fall 2016
C++ Reference NYU Digital Electronics Lab Fall 2016 Updated on August 24, 2016 This document outlines important information about the C++ programming language as it relates to NYU s Digital Electronics
More informationGO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.
http://www.tutorialspoint.com/go/go_operators.htm GO - OPERATORS Copyright tutorialspoint.com An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
More informationJAVA Programming Fundamentals
Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol
More informationProgramming (1.0hour)
COMPETITOR S INSTRUCTION:- Attempt all questions: Where applicable circle the letter that indicates the correct answer. Otherwise answer questions as instructed D1.1 Embedded code is used widely in modern
More informationC++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay
C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming
More informationApplied Computer Programming
Applied Computer Programming Representation of Numbers. Bitwise Operators Course 07 Lect.eng. Adriana ALBU, PhD Politehnica University Timisoara Internal representation All data, of any type, processed
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
More informationECE 375: Computer Organization and Assembly Language Programming
ECE 375: Computer Organization and Assembly Language Programming SECTION OVERVIEW Lab 5 Large Number Arithmetic Complete the following objectives: ˆ Understand and use arithmetic/alu instructions. ˆ Manipulate
More informationEmbedded Systems - FS 2018
Institut für Technische Informatik und Kommunikationsnetze Prof. L. Thiele Embedded Systems - FS 2018 Lab 0 Date : 28.2.2018 Prelab Filling the gaps Goals of this Lab You are expected to be already familiar
More informationVariables and Functions. ROBOTC Software
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
More informationREPETITION CONTROL STRUCTURE LOGO
CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of
More informationMICROPROCESSORS A (17.383) Fall Lecture Outline
MICROPROCESSORS A (17.383) Fall 2010 Lecture Outline Class # 03 September 21, 2010 Dohn Bowden 1 Today s Lecture Syllabus review Microcontroller Hardware and/or Interface Programming/Software Lab Homework
More informationLanguage Reference Manual
ALACS Language Reference Manual Manager: Gabriel Lopez (gal2129) Language Guru: Gabriel Kramer-Garcia (glk2110) System Architect: Candace Johnson (crj2121) Tester: Terence Jacobs (tj2316) Table of Contents
More informationJAVA OPERATORS GENERAL
JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
More informationComputer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons
Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite
More informationZheng-Liang Lu Java Programming 45 / 79
1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius
More informationQUIZ: What value is stored in a after this
QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer
More informationLecture 05 I/O statements Printf, Scanf Simple statements, Compound statements
Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple
More informationEmbedded programming, AVR intro
Applied mechatronics, Lab project Embedded programming, AVR intro Sven Gestegård Robertz Department of Computer Science, Lund University 2017 Outline 1 Low-level programming Bitwise operators Masking and
More informationAll copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva
All copyrights reserved - KV NAD, Aluva Dinesh Kumar Ram PGT(CS) KV NAD Aluva Overview Looping Introduction While loops Syntax Examples Points to Observe Infinite Loops Examples using while loops do..
More informationFlow Control. CSC215 Lecture
Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements
More informationWill introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators
Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships
More informationCGS 3066: Spring 2015 JavaScript Reference
CGS 3066: Spring 2015 JavaScript Reference Can also be used as a study guide. Only covers topics discussed in class. 1 Introduction JavaScript is a scripting language produced by Netscape for use within
More informationSECTION II: LANGUAGE BASICS
Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators
More informationMaciej Sobieraj. Lecture 1
Maciej Sobieraj Lecture 1 Outline 1. Introduction to computer programming 2. Advanced flow control and data aggregates Your first program First we need to define our expectations for the program. They
More informationC OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure
C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces
More informationCP FAQS Q-1) Define flowchart and explain Various symbols of flowchart Q-2) Explain basic structure of c language Documentation section :
CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart ANS. Flowchart:- A diagrametic reperesentation of program is known as flowchart Symbols Q-2) Explain basic structure of c language
More informationData Types and Variables in C language
Data Types and Variables in C language Disclaimer The slides are prepared from various sources. The purpose of the slides is for academic use only Operators in C C supports a rich set of operators. Operators
More informationUIC. C Programming Primer. Bharathidasan University
C Programming Primer UIC C Programming Primer Bharathidasan University Contents Getting Started 02 Basic Concepts. 02 Variables, Data types and Constants...03 Control Statements and Loops 05 Expressions
More informationChapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the
More informationBasic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island
Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types
More informationShort introduction to C for AVR
Short introduction to C for AVR (http://winavr.scienceprog.com/short-introduction-to-c), (www.smileymicros.com), (https://ccrma.stanford.edu/wiki/avr_programming#anatomy_of_a_c_program_for_avr) (AVR035:
More informationC OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed
C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages
More informationPLT Fall Shoo. Language Reference Manual
PLT Fall 2018 Shoo Language Reference Manual Claire Adams (cba2126) Samurdha Jayasinghe (sj2564) Rebekah Kim (rmk2160) Cindy Le (xl2738) Crystal Ren (cr2833) October 14, 2018 Contents 1 Comments 2 1.1
More informationLab 01 Arduino 程式設計實驗. Essential Arduino Programming and Digital Signal Process
Lab 01 Arduino 程式設計實驗 Essential Arduino Programming and Digital Signal Process Arduino Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's
More informationCourse Outline. Introduction to java
Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.
More informationWhy embedded systems?
MSP430 Intro Why embedded systems? Big bang-for-the-buck by adding some intelligence to systems. Embedded Systems are ubiquitous. Embedded Systems more common as prices drop, and power decreases. Which
More informationObject oriented programming. Instructor: Masoud Asghari Web page: Ch: 3
Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning
More informationThe Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and
The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y
More informationCourse Outline Introduction to C-Programming
ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,
More informationChapter 4 Introduction to Control Statements
Introduction to Control Statements Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives 2 How do you use the increment and decrement operators? What are the standard math methods?
More informationThe Arithmetic Operators
The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x
More information/* defines are mostly used to declare constants */ #define MAX_ITER 10 // max number of iterations
General Framework of a C program for MSP430 /* Compiler directives (includes & defines) come first */ // Code you write in this class will need this include #include msp430.h // CCS header for MSP430 family
More informationCENG 447/547 Embedded and Real-Time Systems. Review of C coding and Soft Eng Concepts
CENG 447/547 Embedded and Real-Time Systems Review of C coding and Soft Eng Concepts Recall (C-style coding syntax) ; - Indicate the end of an expression {} - Used to delineate when a sequence of elements
More informationCS50 Supersection (for those less comfortable)
CS50 Supersection (for those less comfortable) Friday, September 8, 2017 3 4pm, Science Center C Maria Zlatkova, Doug Lloyd Today s Topics Setting up CS50 IDE Variables and Data Types Conditions Boolean
More informationObjectives. In this chapter, you will:
Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about
More informationBy the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program
1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize
More informationReserved Words and Identifiers
1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the
More information3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.
Chapter 2: Problem Solving Using C++ TRUE/FALSE 1. Modular programs are easier to develop, correct, and modify than programs constructed in some other manner. ANS: T PTS: 1 REF: 45 2. One important requirement
More informationCS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation
CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;
More informationIn Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.
CS101, Mock Boolean Conditions, If-Then Boolean Expressions and Conditions The physical order of a program is the order in which the statements are listed. The logical order of a program is the order in
More informationC++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5
C++ Data Types Contents 1 Simple C++ Data Types 2 2 Quick Note About Representations 3 3 Numeric Types 4 3.1 Integers (whole numbers)............................................ 4 3.2 Decimal Numbers.................................................
More informationVariables and Operators 2/20/01 Lecture #
Variables and Operators 2/20/01 Lecture #6 16.070 Variables, their characteristics and their uses Operators, their characteristics and their uses Fesq, 2/20/01 1 16.070 Variables Variables enable you to
More informationOur Strategy for Learning Fortran 90
Our Strategy for Learning Fortran 90 We want to consider some computational problems which build in complexity. evaluating an integral solving nonlinear equations vector/matrix operations fitting data
More informationAdvanced Activities - Information and Ideas
Advanced Activities - Information and Ideas Congratulations! You successfully created and controlled the robotic chameleon using the program developed for the chameleon project. Here you'll learn how you
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All for repetition statement do while repetition statement switch multiple-selection statement break statement continue statement Logical
More informationCoding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic.
Coding Workshop Learning to Program with an Arduino Lecture Notes Table of Contents Programming ntroduction Values Assignment Arithmetic Control Tests f Blocks For Blocks Functions Arduino Main Functions
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine
More informationJava is an objet-oriented programming language providing features that support
Java Essentials CSCI 136: Spring 2018 Handout 2 February 2 Language Basics Java is an objet-oriented programming language providing features that support Data abstraction Code reuse Modular development
More informationSAINT2. System Analysis Interface Tool 2. Emulation User Guide. Version 2.5. May 27, Copyright Delphi Automotive Systems Corporation 2009, 2010
SAINT2 System Analysis Interface Tool 2 Emulation User Guide Version 2.5 May 27, 2010 Copyright Delphi Automotive Systems Corporation 2009, 2010 Maintained by: SAINT2 Team Delphi www.saint2support.com
More informationAccelerating Information Technology Innovation
Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lección 03 Control Structures Agenda 1. Block Statements 2. Decision Statements 3. Loops 2 What are Control
More informationLe L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators
Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One
More informationComputational Physics Operating systems
Computational Physics numerical methods with C++ (and UNIX) 2018-19 Fernando Barao Instituto Superior Tecnico, Dep. Fisica email: fernando.barao@tecnico.ulisboa.pt Computational Physics 2018-19 (Phys Dep
More informationTime now to look at how main causes the three LaunchPad LEDs to flash in sequence.
Time now to look at how main causes the three LaunchPad LEDs to flash in sequence. Here is main again (Figure 1). Figure 1 main listing from Lab2 I ve already covered the #include statements and the basic
More informationEmbedded Systems - FS 2018
Institut für Technische Informatik und Kommunikationsnetze Prof. L. Thiele Embedded Systems - FS 2018 Sample solution to Lab 0 Date : 28.2.2018 Prelab Filling the gaps Goals of this Lab You are expected
More informationAN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University
AN OVERVIEW OF C, PART 3 CSE 130: Introduction to Programming in C Stony Brook University FANCIER OUTPUT FORMATTING Recall that you can insert a text field width value into a printf() format specifier:
More informationGridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.
GridLang: Grid Based Game Development Language Language Reference Manual Programming Language and Translators - Spring 2017 Prof. Stephen Edwards Akshay Nagpal Dhruv Shekhawat Parth Panchmatia Sagar Damani
More information