Go Down

Topic: Having trouble on solving the following tasks (Read 5 times) previous topic - next topic

Jonraptor

All i can say is, thanks a lot for your time and patience for solving this issue with me. I am sorry if i have been harsh trying to solve this problem. But, it's sure is worth to know that the Array usually starts at 0 and ends with 9 if the row is equals to 10, and the column starts with 0 and ends with 1 if the cols is equals to 2.

Thank you a lot for your time and patience with me :). There is another task that i am trying to solve as well, but for now. let me get this code organized.

Jonraptor

Yes, ill put the for loops back once im done with arranging my code. Once im done, ill display what i've altered with the output :)

AWOL

The thing to remember here is that the compiled code (when it is that simple and that explicit) rarely lies.
If you see that a result that is being printed when perhaps you don't expect it to be, check and double check the conditions and fit the result to the observation.

I realised as soon as you typed your interpretation of the table values what the problem was, but you found it yourself from my correction, and you gained a valuable lesson about arrays which will stick in your mind better than if I had simply told you.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

I'm curious why the values in the 2nd column of the lookup table are in decreasing order. I find it easier to understand when a value is in range when the lookup table is in increasing order.

Jonraptor

#44
Oct 04, 2012, 04:00 pm Last Edit: Oct 04, 2012, 05:18 pm by Jonraptor Reason: 1
Here is my modified version of my code: -
Code: [Select]

const int ThermPin = A0;
const int rows = 10;
const int cols = 2;
int Table[rows][cols] ={   //col 0||col 1
                            { 25, 4470 }, //row 0
                            { 26, 4250 }, //row 1
                            { 27, 4030 }, //row 2
                            { 28, 3800 }, //row 3
                            { 29, 3530 }, //row 4
                            { 30, 3270 }, //row 5
                            { 31, 3200 }, //row 6
                            { 32, 3170 }, //row 7
                            { 33, 3100 }, //row 8
                            { 34, 3070 }  //row 9
                       };   
void setup()
{
  Serial.begin(9600);
}

void loop()
{

float Vin = 5.0;
float ThermResist = 0.0;
float R2 = 10000.0;
float SensorValue = 0.0;
float Vout = 0.0;
                         
  SensorValue = analogRead(ThermPin);
  Serial.print("Value = ");
  Serial.print(SensorValue);
 
  Vout = (((SensorValue+1)*Vin)/1024.0);
  Serial.print("\t Voltage = ");
  Serial.print(Vout);
  Serial.print(" V");
 
  ThermResist =((R2*Vin)/Vout)-R2;
  Serial.print("\t Resistance = ");
  Serial.print(ThermResist);
  Serial.println(" Ohm");
 
  for (int i = 0; i<rows; i++)
  {
   for(int j = 0;j<cols; j++)
   {
      if(ThermResist >= Table[2][1] && ThermResist <= Table[0][1] )
      {
        Serial.print(Table[0][0]);
        Serial.println(" C");     
      }
      if(ThermResist >= Table[4][1] && ThermResist <= Table[3][1] )
      {
        Serial.print(Table[3][0]);
        Serial.println(" C");
      }
      if(ThermResist >= Table[6][1] && ThermResist <= Table[5][1] )
      {
        Serial.print(Table[5][0]);
        Serial.println(" C");
      }
      if(ThermResist >= Table[9][1] && ThermResist <= Table[7][1] )
      {
        Serial.print(Table[9][0]);
        Serial.println(" C");
      }
    i++;
   }
  j++;
  }

}


And here is the output to that (Works like a charm :D!): -
Code: [Select]

Value = 685.00 Voltage = 3.35 V Resistance = 4927.11 Ohm
Value = 688.00 Voltage = 3.36 V Resistance = 4862.12 Ohm
Value = 693.00 Voltage = 3.39 V Resistance = 4755.04 Ohm
Value = 695.00 Voltage = 3.40 V Resistance = 4712.64 Ohm
Value = 698.00 Voltage = 3.41 V Resistance = 4649.50 Ohm
Value = 701.00 Voltage = 3.43 V Resistance = 4586.89 Ohm
Value = 704.00 Voltage = 3.44 V Resistance = 4524.82 Ohm
Value = 707.00 Voltage = 3.46 V Resistance = 4463.28 Ohm
25 C
25 C
25 C
25 C
25 C
25 C
25 C
Value = 729.00 Voltage = 3.56 V Resistance = 4027.40 Ohm
Value = 733.00 Voltage = 3.58 V Resistance = 3950.95 Ohm
Value = 731.00 Voltage = 3.57 V Resistance = 3989.07 Ohm
Value = 731.00 Voltage = 3.57 V Resistance = 3989.07 Ohm
Value = 733.00 Voltage = 3.58 V Resistance = 3950.95 Ohm
Value = 733.00 Voltage = 3.58 V Resistance = 3950.95 Ohm
Value = 739.00 Voltage = 3.61 V Resistance = 3837.84 Ohm
Value = 737.00 Voltage = 3.60 V Resistance = 3875.34 Ohm
Value = 739.00 Voltage = 3.61 V Resistance = 3837.84 Ohm
Value = 740.00 Voltage = 3.62 V Resistance = 3819.16 Ohm
Value = 740.00 Voltage = 3.62 V Resistance = 3819.16 Ohm
Value = 742.00 Voltage = 3.63 V Resistance = 3781.96 Ohm
28 C
28 C
28 C
28 C
28 C
28 C
Value = 756.00 Voltage = 3.70 V Resistance = 3527.08 Ohm
Value = 756.00 Voltage = 3.70 V Resistance = 3527.08 Ohm
Value = 756.00 Voltage = 3.70 V Resistance = 3527.08 Ohm
Value = 756.00 Voltage = 3.70 V Resistance = 3527.08 Ohm
Value = 768.00 Voltage = 3.75 V Resistance = 3316.00 Ohm
Value = 768.00 Voltage = 3.75 V Resistance = 3316.00 Ohm
Value = 769.00 Voltage = 3.76 V Resistance = 3298.70 Ohm
Value = 771.00 Voltage = 3.77 V Resistance = 3264.25 Ohm
30 C
30 C
30 C
30 C
30 C
30 C
Value = 775.00 Voltage = 3.79 V Resistance = 3195.88 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 775.00 Voltage = 3.79 V Resistance = 3195.88 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 775.00 Voltage = 3.79 V Resistance = 3195.88 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 777.00 Voltage = 3.80 V Resistance = 3161.95 Ohm
34 C
34 C
34 C
34 C
34 C
Value = 775.00 Voltage = 3.79 V Resistance = 3195.88 Ohm
Value = 775.00 Voltage = 3.79 V Resistance = 3195.88 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm
Value = 776.00 Voltage = 3.79 V Resistance = 3178.89 Ohm


Go Up