Hi, I'm working on a project that involves a bit of complicated measuring temperature via voltage on the TI-84 CE. I seem to have the code working but it just stops after 1 loop. Can anyone help me out?


Code:

Send("CONNECT LED 1 TO BB 1")
Send("CONNECT LED 2 TO BB 2")
Send("CONNECT LED 3 TO BB 3")
Send("CONNECT ANALOG.IN 1 TO BB 5")
Input "M = ?", M
Input "B = ?", B
For(N,1,200)
   Send("READ ANALOG.IN 1")
   Get(A)
   M*A+B->C
   Disp A
   If 0<C<37
   Then
      Send("SET LED 3 TO ON")
      Disp "BLUE LED IS ON"
      Disp "Temperature in C",C
      Wait .5
   Else
      Send("SET LED 3 TO OFF")
      
      If 37<C<212
         Then
         Send("SET LED 2 TO ON")
         Disp "GREEN LED IS ON"
         Disp "Temperature in C",C
         Wait .5
      Else
         Send("SET LED 2 TO OFF")

         If C>=212
            Then
            Send("SET LED 1 TO ON")
            Disp "RED LED IS ON"
            Disp "Temperature in C",C
            Wait .5
         Else
            Send("SET LED 1 TO OFF")
      End
Welcome to Cemetech!

It looks like the first if-then statement and the for loop do not have the necessary "End" tokens. This will make the code only execute once and then exit.

If you have any more questions, please let us know! Smile
Captain Calc wrote:
Welcome to Cemetech!

It looks like the first if-then statement and the for loop do not have the necessary "End" tokens. This will make the code only execute once and then exit.

If you have any more questions, please let us know! Smile


Can you elaborate? When you say End tokens do you mean I should include an end after each if then statements? I've had experience with other languages before but I'm not exactly sure what I'm doing when it comes to a calculator.
Imparssio wrote:
When you say End tokens do you mean I should include an end after each if then statements?
Yes.

Stripping away extra code, here is the structure of your code:

Code:
For
   If
   Then
      //code
   Else
      If
      Then
         //code
      Else
         If
         Then
            //code
         Else
            //code
         End

Imparssio wrote:
I've had experience with other languages before

Okay, let's switch C syntax then:

Code:
for () {       // For(
  if () {      // If :Then
  } else {     // Else
    if () {    // If :Then
    } else {   // Else
      if () {  // If :Then
      } else { // Else
      }        // End
It should become clear you are missing three closing brackets, which in TI-BASIC equates to three End tokens.
LogicalJoe wrote:
Imparssio wrote:
When you say End tokens do you mean I should include an end after each if then statements?
Yes.

Stripping away extra code, here is the structure of your code:

Code:
For
   If
   Then
      //code
   Else
      If
      Then
         //code
      Else
         If
         Then
            //code
         Else
            //code
         End

Imparssio wrote:
I've had experience with other languages before

Okay, let's switch C syntax then:

Code:
for () {       // For(
  if () {      // If :Then
  } else {     // Else
    if () {    // If :Then
    } else {   // Else
      if () {  // If :Then
      } else { // Else
      }        // End
It should become clear you are missing three closing brackets, which in TI-BASIC equates to three End tokens.


Ok, that makes sense when you explain it in the syntax in C. I worked it out like that and now my program works, the only issue now is that it's measuring around 27.88 Celsius and turns on both the blue light and green light instead of only the blue. Also it seems that when the temperature reaches 37 (I changed it instead to be C has to be greater than or equal to 37) the blue LED does not turn off. It seems that it skips over the else statements now and I'm not sure why.
Alright, 0<C<37 in BASIC executes as (0<C)<37 Which is not what you want, you want 0<C and C<37.
The first If statement needs to turn off the LED above it as well, so the first If should look like:
Code:
   If 0<C and C<37
   Then
      Send("SET LED 2 TO OFF")
      Send("SET LED 3 TO ON")
      Disp "BLUE LED IS ON"
      Disp "Temperature in C",C
      Wait .5
   Else
...

Scratch that, better idea: Use separate if-else clauses to handle each light.

Code:
   If 0<C and C<37
   Then
      Send("SET LED 3 TO ON"
      Disp "BLUE LED IS ON"
   Else
      Send("SET LED 3 TO OFF"
   End
   If 37<C and C<212
   Then
      Send("SET LED 2 TO ON"
      Disp "GREEN LED IS ON"
   Else
      Send("SET LED 2 TO OFF"
   End
   If C>=212
   Then
      Send("SET LED 1 TO ON"
      Disp "RED LED IS ON"
   Else
      Send("SET LED 1 TO OFF"
   End
   Disp "Temperature in C",C
   Wait .5
Thanks @LogicalJoe!I just came from a Java class so I was thinking of just using && but couldn't find the and statement so I just tried what people would do in math! Everything seems to be working though now. It's a bit messy compared to the example given (the example was using an Inspire CX) but it seems to read accurately now! Cheers! Very Happy
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement