Calculate the average value from two sensors

Hello everybody,
I have a question about the programming of Arduino,
I want to use two sensors to measure the average temperature (T1+T2/2) and then make it usable as fuzzy logic input.

First, I transformed the file (.fis) into an arduino code through the website Arduino FIST: MATLAB Fuzzy Inference System to Arduino Conversion ( See the code bellow).

Can someone help me in this task?

#include "fis_header.h"


// Number of inputs to the fuzzy inference system
const int fis_gcI = 2;
// Number of outputs to the fuzzy inference system
const int fis_gcO = 1;
// Number of rules to the fuzzy inference system
const int fis_gcR = 9;


FIS_TYPE g_fisInput[fis_gcI];
FIS_TYPE g_fisOutput[fis_gcO];

// Setup routine runs once when you press reset:
void setup()

{
  Serial.begin(9600);

  // initialize the Analog pins for input.
  // Pin mode for Input: Temperature pin 0
  pinMode(A0 , INPUT);
  // Pin mode for Input: Temperature pin 1
  pinMode(A1 , INPUT);

  // initialize the Analog pins for output.
  pinMode(11 , OUTPUT);

}

// Loop routine runs over and over again forever:


void loop()
{
  // Read Input: Temperature from sensor 1
  g_fisInput[0] = analogRead(A0);

  // Read Input: Temperature from sensor 2
  g_fisInput[1] = analogRead(A1);


  g_fisOutput[0] = 0;

  fis_evaluate();

  analogWrite(11 , g_fisOutput[0]);
  
}

//***********************************************************************
// Support functions for Fuzzy Inference System
//***********************************************************************
// Trapezoidal Member Function
FIS_TYPE fis_trapmf(FIS_TYPE x, FIS_TYPE* p)
{
  FIS_TYPE a = p[0], b = p[1], c = p[2], d = p[3];
  FIS_TYPE t1 = ((x <= c) ? 1 : ((d < x) ? 0 : ((c != d) ? ((d - x) / (d - c)) : 0)));
  FIS_TYPE t2 = ((b <= x) ? 1 : ((x < a) ? 0 : ((a != b) ? ((x - a) / (b - a)) : 0)));
  return (FIS_TYPE) min(t1, t2);
}

// Triangular Member Function
FIS_TYPE fis_trimf(FIS_TYPE x, FIS_TYPE* p)
{
  FIS_TYPE a = p[0], b = p[1], c = p[2];
  FIS_TYPE t1 = (x - a) / (b - a);
  FIS_TYPE t2 = (c - x) / (c - b);
  if ((a == b) && (b == c)) return (FIS_TYPE) (x == a);
  if (a == b) return (FIS_TYPE) (t2 * (b <= x) * (x <= c));
  if (b == c) return (FIS_TYPE) (t1 * (a <= x) * (x <= b));
  t1 = min(t1, t2);
  return (FIS_TYPE) max(t1, 0);
}

FIS_TYPE fis_min(FIS_TYPE a, FIS_TYPE b)
{
  return min(a, b);
}

FIS_TYPE fis_max(FIS_TYPE a, FIS_TYPE b)
{
  return max(a, b);
}

FIS_TYPE fis_array_operation(FIS_TYPE *array, int size, _FIS_ARR_OP pfnOp)
{
  int i;
  FIS_TYPE ret = 0;

  if (size == 0) return ret;
  if (size == 1) return array[0];

  ret = array[0];
  for (i = 1; i < size; i++)
  {
    ret = (*pfnOp)(ret, array[i]);
  }

  return ret;
}

What have you tried?

Paul

There are two ways to solve this problem:

add caclulating the average (T1 + T 2) / 2 to your FIS-file.
and let do the transformation from FIS to Arduino by the website

learn programming Arduino-C++

best regards Stefan