Saturday, May 28, 2016

TI-Innovator Light Meter

My previous post was about a "first" program on TI-Innovator. But, most of the idea was from something else I had already done, so it was more of an adaptation of an already done task than a new idea. But it gave me the idea for my second program. The Innovator has an on-board light sensor, which gives readout of light intensity as a decimal number from 0 to 100. I thought to tie my LED array in to the sensor readout to create a digital light intensity gauge.

The LED array is same is in my Knight Rider program -- 10 LED on a breadboard with inline resistors, jumpered to the breadboard pinout and ground from Innovator. Challenge was to modify my program to light a number of LED in the array based on the sensor readout.

Basic ideas weren't hard. I have 10 LED, so divide the readout by 10, and then use a floor function to convert it to integer (used Int(... which is a standard TI-84 function). Then modify my lighting loop, instead of going 1 to 10, go from 1 to whatever the readout specified.

But I also wanted it to go down when light intensity decreased. This threw me for a little while in one of those good ways that is obvious after you thought about it, but is also why coding is a good activity for the brain. (thanks Jo Boaler. my brain grew.) The key was, unlight pin numbers to one greater than the sensor output.

The way I wrote the program, I also echo the sensor reading to the TI-84 screen. I'm sure I could code this much cleaner if I spent some time on it. Here's a short video showing it in operation. It's a cloudy day, so I couldn't get a very high light reading. This morning I was pinning the sensor at 10.



One of the things that bothers me about my program is, I don't know how to quit cleanly. I can force a quit by pressing [on] on the calculator, but that sends an error message to the screen. I also don't know why but sometimes when I run a program, the Innovator Hub beeps. The program still runs, but I assume the beeping is indicating some error state.

Anyhow, that's my exploration. It was fun borrowing the Innovator for a few days. Now I've got to return it. Thank you Texas Instruments Education Products.

*** edit 2016 May 28 16:23 ***
I'm a little embarrassed of the quality of my code, but some have asked, so here's the program that ran my meter. I'm sure it could be made much cleaner and elegant.:
For(N,1,10)
Send("CONNECT LED eval(N) TO BB eval(N)
End
0→B
0→L
While 1
Send("READ BRIGHTNESS ")
Get(B)
int(B/10)→B
Disp B
If B>L
Then
For(N,1,B)
Send("SET LED eval(N) ON")
End
Else
If B<L
Then
For(N,10,B+1,­1)
Send("SET LED eval(N) OFF")
End
Else
Disp B
End
End
Wait .2
B→L
End

No comments:

Post a Comment