Sample Programs

Use the following Sample Programs to become familiar with methods from the Reference section. These samples also contain several TI-Innovator™ Hub and
TI-Innovator Rover™ programs to help you get started with TI-Python.

Topic Links


COLORLIN

import ti_plotlib as plt

plt.cls()

plt.window(-10,10,-10,10)

plt.axes("on")

plt.grid(1,1,"dot")

plt.title("TITLE")

plt.pen("medium","solid")

plt.color(28,242,221)

plt.pen("medium","dash")

plt.line(-5,5,5,-5,"")

plt.color(224,54,243)

plt.line(-5,-5,5,5,"")

plt.show_plot()

Press to display the Shell prompt


REGEQ1

First, enter two lists in the CE OS. Then, for example, calculate [stat] CALC 4:LinReg(ax+b) for your lists. This stores the regression equation to RegEQ in the OS. Here is a program to recall RegEQ to the Python experience.

# Example of recall_RegEQ()

from ti_system import *

 

reg=recall_RegEQ()

print(reg)

x=float(input("Input x = "))

print("RegEQ(x) = ",eval(reg))



LINREGR (Provided in CE Bundle)

import ti_plotlib as plt

 

# current intensity

I = [0.0, 0.9, 2.1, 3.1, 3.9, 5.0, 6.0, 7.1, 8.0, 9.2, 9.9, 11.0,11.9]

 

# voltage

for n in range (len(I)):

I[n] /= 1000

 

# la tension

U = [0, 1, 2, 3.2, 4, 4.9, 5.8, 7, 8.1, 9.1, 10, 11.2, 12]

 

plt.cls()

plt.auto_window(I,U)

plt.pen("thin","solid")

plt.axes("on")

plt.grid(.002,2,"dot")

plt.title("Ohm's Law")

plt.color (0,0,255)

plt.labels("I","U",11,2)

plt.scatter(I,U,"x")

plt.color (255,0,0)

plt.pen("thin","dash")

plt.lin_reg(I,U,"center",2)

plt.show_plot()

plt.cls()

a=plt.a

b=plt.b

print ("a =",round(plt.a,2))

print ("b =",round(plt.b,2))

Press to display the Shell prompt



GRAPH (Provided in CE Bundle)

import ti_plotlib as plt

#After running the program, press [clear] to clear plot and return to Shell.

 

def f(x):

••return 3*x**2-.4

 

def g(x):

••return -f(x)

 

def plot(res,xmin,xmax):

••#setup plotting area

••plt.window(xmin,xmax,xmin/1.5,xmax/1.5)

••plt.cls()

••gscale=5

••plt.grid((plt.xmax-plt.xmin)/gscale*(3/4),(plt.ymax-plt.ymin)/gscale,"dash")

••plt.pen("thin","solid")

••plt.color(0,0,0)

••plt.axes("on")

••plt.labels("abscisse"," ordonnee",6,1)

••plt.pen("medium","solid")

 

# plot f(x) and g(x)

dX=(plt.xmax -plt.xmin)/res

x=plt.xmin

x0=x

••for i in range(res):

••••plt.color(255,0,0)

••••plt.line(x0,f(x0),x,f(x),"")

••••plt.color(0,0,255)

••••plt.plot(x,g(x),"o")

••••x0=x

••••x+=dX

••plt.show_plot()

 

#plot(resolution,xmin,xmax)

plot(30,-1,1)

# Create a graph with parameters(resolution,xmin,xmax)

# After clearing the first graph, press the [var] key. The plot() function allows you to change the display settings (resolution,xmin,xmax).

 

Press to display the Shell prompt



DASH1 – Sample TI-Innovator™ Hub Program

See: [Fns…]>Modul: ti_hub module

from ti_system import *

import brightns

import ti_plotlib as plt

from time import *

 

plt.cls()

plt.color(0,0,255)

plt.text_at(2,"Monitoring Hub","center")

plt.text_at(3,"Brightness Sensor","center")

plt.color(255,0,0)

plt.text_at(12,"Press [clear] to quit ","right")

t0=monotonic()

plt.color(0,0,0)

while not escape():

••I=brightns.measurement()

••I=round(I,1)

••tf=monotonic()

••plt.color(0,0,0)

••tm=round(tf-t0,1)

••msg="Time = %.1f sec" % tm

••plt.text_at(6,msg,"center")

••msg="Brightness = %.1f %%" %I

••plt.text_at(7,msg,"center")

••sleep(1)



ROVER – Sample TI-Innovator™ Rover program

See: [Fns…]>Modul ti_rover module

from ti_system import *

import ti_rover as rv

disp_clr()

disp_cursor(0)

disp_at(6,"Press [clear] to stop","center")

rv.forward(20)

while not escape():

••a=rv.ranger_measurement()

••if a<0.2:

••••rv.color_rgb(255,0,0)

••••rv.stop()

••else:

••••rv.color_rgb(0,255,0)

••••rv.resume()

rv.stop()

disp_clr()

rv.color_rgb(0,0,255)

sleep(1)

rv.color_rgb(0,0,0)



BLNKSND - Sample TI-Innovator™ Hub Program

See: [Fns…]>Modul: ti_hub module



SQUARE - Sample TI-Innovator™ Rover Program

See: [Fns…]>Modul ti_rover module



STOP_GO - Sample ti_draw, ti_image, time Program

See:[Fns…]>Modul [Add-On]

from ti_draw import *

from ti_image import *

from time import *

clear()

# Pixel screen upper left (0,0) to (319,209)

draw_text(100,20,"Traffic Light")

set_pen("medium","solid")

 

draw_rect(120,25,80,175)

set_color(192,192,192)

fill_rect(120,25,80,175)

set_color(128,128,128)

draw_circle(160,55,22)

draw_circle(160,110,22)

draw_circle(160,165,22)

 

def off(x,y):

••set_color(169,169,169)

••fill_circle(x,y,22)

••set_color(128,128,128)

••draw_circle(x,y,22)

 

for i in (1,20,1):

# Green

••set_color(51,165,50)

••fill_circle(160,165,22)

••sleep(3)

••off(160,165)

# Yellow

••set_color(247,239,10)

••fill_circle(160,110,22)

••sleep(2)

••off(160,110)

# Red

••set_color(255,0,0)

••fill_circle(160,55,22)

••sleep(3)

••off(160,55)

••show_draw()