ti-nspire programming

17
TI-Nspire Programming An Introduction Josh Schneider [email protected]

Upload: ziarre

Post on 16-Mar-2016

38 views

Category:

Documents


2 download

DESCRIPTION

TI-Nspire Programming. An Introduction. Josh Schneider [email protected]. Who this session is for…. “ I’ve never programmed on anything, ever; but I have this class set of TI- Nspires … ” These guys might benefit too, but some material will be stuff you already know… - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: TI-Nspire Programming

TI-Nspire ProgrammingAn Introduction

Josh [email protected]

Page 2: TI-Nspire Programming

Who this session is for…

“I’ve never programmed on anything, ever; but I have this class set of TI-Nspires…”

These guys might benefit too, but some material will be stuff you already know… “I’ve never programmed on a calculator before, but I’ve done

some little scripts here and there on my computer.” “I’ve never programmed on the Nspire before, but I have

worked on other TI products.” Who will be really bored…

“I’ve not only done a ton of TI-Basic programs, I’ve also written a few Apps!”

Page 3: TI-Nspire Programming

Why Programming?

1. Programming is a passion of mine. Logic is fun!2. The amount of work to do always increases, while

the amount of people to do it almost never does. I feel that truly effective people find ways to automate repetitive tasks in their every day life.

3. For some students, Programming is a tangible way to teach abstract concepts of logic, causality, critical thinking, and even empathy!

Page 4: TI-Nspire Programming

“Progra– what?”

An Algorithm is a list of instructions to accomplish a goal.

Think of an Algorithm as a Recipe Ingredients become Variable Declarations Steps become Code Yield becomes Return

The digital expression of your Algorithm is a Program.

Page 5: TI-Nspire Programming

Scripts vs Programs – An Aside

A Programming Language must be translated from the language to machine language (a process called Compiling, using a Compiler) before it can be executed. Changes take time, you have to recompile each time you want

to run. A Scripting Language is translated from the language to

machine language at runtime (Interpreting) using a piece of software called an Interpreter. Changes can be made and tested “on the fly”. Easier to debug.

TI BASIC is technically a scripting language.

Page 6: TI-Nspire Programming

Prgm vs Func

In the world of the TI-Nspire… A Program (Prgm) is an expression of an algorithm.

Variables can be local or global. Does not return a response… just output.

A Function (Func) is an expression of an algorithm that returns a response. Variables must be local. The Function must return a response. Most of the commands you use in the TI-Nspire are

Functions.

Page 7: TI-Nspire Programming

Some Terminology

Debugging is the process of stepping through code, finding, and fixing issues.

A Block is “container for code”. An example, the Prgm and EndPrgm statements form a Prgm Block. Everything between those statements are treated as a program.

A Conditional statement offers boolean criteria (true or false) and effects based on the response, essentially a choice for the program.

A Loop allow you to repeat steps. A loop allow you to repeat steps. A loop allow you to repeat steps…

Page 8: TI-Nspire Programming

Error Terminology

A Syntax Error generally means that you used a function or command incorrectly. For instance: Solve(2x=0) would produce a syntax error,

since the Solve() command requires an expression, a comma, and then a variable.

A Domain Error generally indicates that a calculation is out of the range of the calculator’s capabilities.

Page 9: TI-Nspire Programming

Logic Errors

The beauty of code: It does exactly what you tell it to do.

The frustration of code: It does exactly what you tell it to do.

Logic Errors are errors in which the commands and functions are used in their proper syntax, but the code doesn’t produce the expected outcome. This is usually because of human errors in planning. These types of issues are common. At some point, every good

programmer ends up crawling lines of code looking for an errant line. It’s a rewarding find.

Page 10: TI-Nspire Programming

The Program Editor So here’s how to get started programming:

On the device:1. Insert a calculator

page.2. Press Menu3. Choose 9:Functions &

Programs4. Choose 1:Program

Editor5. Choose 1:New…

On the software:1. Insert a calculator

page.2. Click on 9:Functions &

Programs3. Choose 1:Program

Editor4. Choose 1:New…• Once you’re here, start filling in the name of your program, choosing whether it’s a program or a function, and setting its library access.

Page 11: TI-Nspire Programming

Library Access?

LibPriv means that the function or program will be available from any document, but will not display in the catalog.

LibPub means that the function or program will be available from any document, and will display in the catalog.

None or leaving out LibPriv/LibPub means that the function or program will only be accessible from the current document. (This is the default)

You can write your functions or programs in one document using LibPriv or LibPub, and then access those programs or functions from any document!

Page 12: TI-Nspire Programming

00110110

01001101

11001001

10110110

Program #1 – Hello World

Define hello()=Prgm Disp “Hello World!”EndPrgm

The “Hello World” program is the most common example of a new programming language. It is the simplest program that can be written, as it requires no input, and simply outputs the text “Hello World”.

A “Hello World” program is a good way to learn the most basic structure of a programming language.

Page 13: TI-Nspire Programming

00110110

01001101

11001001

10110110

Program #2 – Random List Generator

Define randgen(a)=FuncLocal b,iFor i,1,a,1 b[i]:=RandInt(0,9)EndForReturn bEndFunc

With this program, we’ll spice things up by adding a loop and input. Since we want to return a value (making the result useful outside the program itself), we’ll do this one as a function.

For the loop, I chose a For..EndFor loop since we know how many times we want to run through.

The idea is, we run the function specifying how many elements we want, and the function outputs a list of that many random integers between 0-9.

Page 14: TI-Nspire Programming

00110110

01001101

11001001

10110110

Program #3 – Evens or Odds?

Define evenodd(a)=PrgmFor i,1,dim(a),1 If mod(a[i],2)=0 Then Disp a[i],” is even.” Else Disp a[i],” is odd.” EndIfEndForEndPrgm

With this program, we go one step further: we’re adding conditional statements to the loop we already know. This one is being done as a program, but this time we’ll specify an input parameter.

For a conditional, we use If..Then..Else…Endif. The device will evalute the stuff between If and Then, and if it is true, will execute the statements after Then. If the statement is not true, we go to Else, or exit the conditional nothing else is specified.

Page 15: TI-Nspire Programming

Next Steps

Functions are infinitely useful! You can use your functions to manipulate data in Lists and Spreadsheets, on graphs (using the Calculate tool), and in Calculator.

Programs are growing more useful thanks to the TI-Nspire 2.0 addition of the Request and RequestStr commands for taking input.

Always remember to Check Syntax and Save before testing your creations!

Page 16: TI-Nspire Programming

Anticipating the User

Users will do interesting things you did not intend.

Try to keep your users in mind when writing a new program.

Add conditional statements to check incoming data, and return useful error messages to the user or limit your program’s response to the data.

Page 17: TI-Nspire Programming

Questions?

?