+ All Categories
Home > Documents > INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education...

INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education...

Date post: 20-Jan-2016
Category:
Upload: angel-underwood
View: 219 times
Download: 1 times
Share this document with a friend
Popular Tags:
52
INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1
Transcript
Page 1: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

1

INTRODUCTION TO ROBOTICSPart 5: Programming

Robotics and AutomationCopyright © Texas Education Agency, 2013. All rights reserved.

Page 2: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

2

“We live in a society exquisitelydependent on science and technology,in which hardly anyone knowsanything about science and technology” – Carl Sagan, 1990

This statement was made before the Internet andcell phones. It has only become worse since then.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 3: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

3

Technology and Computers

• Technology has become very easy to use.• But just beneath the surface, most

technology is incredibly complex.• Computers are literally the most powerful

problem-solving tools humanity has ever created.

• We all benefit when the knowledge of how to apply those tools is more widely understood in our society.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 4: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

4

Coding and Solving Problems

• The ability to code is not just a way to understand technology.

• The ability to code is a mode of thought and a language in itself—the same as literacy or mathematics.

• Coding involves critical thinking, problem solving, analysis, and logic. It is not about writing code; it is about solving problems.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 5: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

5

It is time to open up the black box!

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 6: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

6

Program Requirements

Programming requires• Something that will run the program

oA computeroA microprocessoroA microcontroller (what we will use!)

• A computer program that lets a user write a computer programoAn IDE

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 7: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

7

Integrated Development Environment• A computer program used to write a computer program

o Allows students to write a computer program that can be downloaded from any PC

o Allows users to write code in a language that is easier to use than the machine level code

• In this case, C and C++o Converts the higher level language to the machine code that is

specific to a family of microprocessorso Allows the microcontroller to perform the instructions and to

interact with the outside world

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 8: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

8

IDE Components

• Editor• Assembler/ Compiler• Simulator• Debugger• Programmer (optional)• Emulator (optional)

An IDE is specific to a device or a family of devices made by a particular manufacturer.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 9: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

9

Choosing a Platform• Robots require programming and instructions to operate.

o When they face a situation outside of their program, they can stop, fail, or crash.

• This makes the microcontroller the key piece of a robot.• There are generic ways of learning about robots, but

generic descriptions can only go so far for teaching.• With generic descriptions, you reach a limit on the

amount of learning and understanding.• You need specific examples, and for specific examples we

need to decide on a platform.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 10: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

10

What is a Microcontroller?• A microcontroller is an entire computer on a chip.

o RAM, ROM, I/O, port controllers, converters, timers, and CPU are integrated as a single system.

• Self contained and sometimes on a single chip • Single purpose• Does not require much processing power• The operating system is simple, contained in ROM,

and has a built in instruction decoder for the language used.

• They are relatively simple and easy to use.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 11: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

11

Microcontrollers

• The world is becoming increasingly electronic, so some type of understanding about how electronics actually work is becoming more important.

• One of the key advantages of a microcontroller is that people can program and use them.

• Microcontrollers go beyond theory because one can quickly enable them to produce the same real world outputs seen everyday.

• At the same time, there is a depth to microcontroller knowledge and application that is virtually unlimited.

• They can be used to create more powerful applications than the individual circuits alone.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 12: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

12

Choosing a Microcontroller We compile a list of features and criteria we want. o The microcontroller’s cost must be low while including a

development board (below $50).o It must be easy to use and well supported. It is important to

have a lot of documentation readily available.o It should be programmed in a useful and common language.o It must be popular and have an active user community.o Since the robot will be used as a general purpose platform, the

microcontroller should be very feature rich in order to allow for broad experimentation. In this sense, it should have several analog and digital pins, as well as an integrated voltage regulator.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 13: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

13

Choosing a Microcontroller• There are many fine examples of microcontrollers to

choose from.• There are a number of very good and popular high-level

programming languages including C, C++, C#, Basic,and more.

• Taking all these factors into consideration, one should choose a microcontroller thato is inexpensive, o uses the C programming language, ando has a variety of inexpensive and available add-on boards.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 14: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

14

Open Source vs. Proprietary

• Choose hardware and software that are open source, which meanso the boards are inexpensive ando the software is simple and flexible.

• Choose open-source technology with a list of public domain resources includingo libraries,o working examples, ando experienced programming support.

• Proprietary software and hardware is controlled, limited, and expensive.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 15: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

15

Why Not a PC?• A PC is expensive

o hundreds of dollars vs. $30

• A PC uses a lot of electrical powero 600 W vs. < .5 W

• A PC is not portableo uses AC not DCo is heavy and bulky

• A PC requires many peripheral componentso keyboard, mouse, RAM, monitor, hard drive

• Many different types of connections to makeo SATA, PATA, PCI, PCIe, VGA, USB, serial, parallel

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 16: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

16

Microcontrollers vs. PC

• One of the key features of PC microprocessors is that they have to be backward compatibleoThis adds to expense and complexityoMotherboards in particular are complex

and expensive• Microcontrollers have fewer and

simpler connections

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 17: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

17

Applied Programming

• Start with a simple example• Interface a simple device to the

microcontroller• The computer program provides

that interface• Combine physical, electrical,

and software

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 18: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

18

Back to the Bumper Switch• A bumper switch produces an output voltage

whether it is open or closed.o Zero volts is recorded as a binary zero (false).o +5 volts is recorded as a binary one (true).

• The values are stored as a variable.• A program loop reads the variable value

thousands of times per second.• The true or false conditions are evaluated by

the conditional loop.• A program function is executed either way.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 19: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

19

The Worlds Simplest Program

This program has every required elementneeded to run in a microcontroller, with proper syntax and formatting. However, it will not actually do anything constructive.

void setup() { // put your setup code here, to run once;}

void loop() { // put your main code here, to run repeatedly; }

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 20: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

20

Program Parts

The first thing to notice is the program has two parts• A part that runs once• A part that runs over and over again

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 21: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

21

Syntax

The next thing to notice is the use of formatting symbols in the program. These symbols form what is called the syntax, which is the language the program uses.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 22: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

22

Syntax

• Each symbol has a particular meaning.• Some of the symbols are required for the

program to be compiled and executed correctly.

• Others define parts of a program such as statements and functions.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 23: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

23

Symbols

• Braces { }, or curly brackets, go around executable program sections called functions. oBoth an opening brace (or left brace) and a

closing brace (or right brace) are needed.• The semicolon ( ; ) ends a program

statement or command.oAn easy way to get a syntax error is to forget

to use a semicolon after a command.Copyright © Texas Education Agency, 2013. All rights reserved.

Page 24: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

24

More Symbols

• The parenthesis after each instruction is required and tells the program that the name used is a function and not something else.oA variable

• The word “void” tells the program that the functions setup () and loop () do not return any values or data.o This word is required or the program will hang up

waiting for data.Copyright © Texas Education Agency, 2013. All rights reserved.

Page 25: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

25

Keywords

• Keywords are words and names that are already defined in the C++ language to perform specific operations.o They must be used correctly for the program to work at all.o Failure to use symbols and keywords correctly results in

something called a syntax error.• You can define your own keywords.

o They must be defined before you use them in a program.

o It is done by naming a procedure.o It creates what is called an abstraction.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 26: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

26

Abstractions

• The main purpose of this part of the lesson is to introduce functions, statements, loops, variables, comments, and the formatting symbols that make up the syntax.

• We will use abstractions in our programming examples.

• This is done primarily to simplify the program.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 27: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

27

Example Program

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 28: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

28

Variables

• A variable must be defined before you can use the variable (example: to store or read data), during initialization, before the main program loop.

• Anytime you have a condition to evaluate youhave data.

• Data requires a name and a memory location.o Defining a variable does both of those things.

• Data size is both how big the number can be and the amount of memory used to store it.o Char = 8 bits (0-255), int = 16 bits (0-65,535)

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 29: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

29

Program Description

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

Assign variablesInt = 16 bits

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 30: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

30

Program Description

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

We like to use names for our pins

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 31: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

31

Program Description

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

And for our data

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 32: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

32

Program Loops

• A program (or program segment) that runs the same section of code over and over

• Necessary when waiting for an input while performing other tasks likeo generating video while waiting for user input,o driving around until bumping into an object, oro performing a particular task only when a specific

condition is present.• Most programs involve one or more loops

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 33: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

33

Types of Loops

• Infinite loopso Usually the main program loopo Can also be the result of a programming erroro Example: while

• Counting loopso Performs an action a specified number of timeso Example: for

• Conditional loopso Performs a specific action as a result of a

specific inputo Example: if, else

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 34: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

34

Program Description

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 35: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

35

Program Description

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

These are comments (not

executed)

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 36: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

36

Program Description

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

These are statements

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 37: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

37

Improved Program

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

Statements are computer commands

terminated with a semicolon ( ; )

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 38: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

38

Improved Program

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

These are called

functions

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 39: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

39

Improved Program

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

Functions are enclosed in

brackets

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 40: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

40

Improved Program

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

Functions are enclosed in

brackets

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 41: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

41

Improved Program

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

Do the stuff in this function

once

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 42: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

42

Improved Program

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

We want to set pin 7 as an input

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 43: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

43

Improved Program

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

Do the stuff in this function over and over

again

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 44: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

44

Improved Program

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

Get the value on pin 7 many times

as we drive around

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 45: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

45

Improved Program

int switchPin = 7; // the number of the pushbutton //pin

int switchdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read the state of the pushbutton value:switchdata = GetDigitalInput(switchPin);}

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 46: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

46

Second Example

• What if we want to read data from an analog sensor?

• An analog sensor has many values over a range, such as temperature.

• We only need to change a few commands from the previous example.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 47: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

47

int analogdata = 0;

analogdata = GetAnalogInput (7);

Use a new name

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 48: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

48

int analogdata = 0;

analogdata = GetAnalogInput (7);

Use a different commandto read analog data

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 49: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

49

Analog Data Program

int switchPin = 7; // the number of the pushbutton //pin

int analogdata = 0; // variable for reading the switch //value

void setup() { // initialize the pushbutton pin as an input:pinMode(switchPin, INPUT); }

void loop() { // read and store the analog value:analogdata = GetAnalogInput(switchPin);}

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 50: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

50

Analog vs. Digital Input

• Not much difference in how you get the data

• Huge difference in what you can do with it

• Binary only has two values and you can only do two things with it

• Analog has many values and you can do many things

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 51: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

51

Analog Input

• This means many decisions and potentially much more complicated programming.

• Use less than or greater than mathematics, more than equals.

Copyright © Texas Education Agency, 2013. All rights reserved.

Page 52: INTRODUCTION TO ROBOTICS Part 5: Programming Robotics and Automation Copyright © Texas Education Agency, 2013. All rights reserved. 1.

52

Learn By Doing

• You have been shown how to get started in programming.

• From here, the only way to learn is to

learn by doing!

Copyright © Texas Education Agency, 2013. All rights reserved.


Recommended