Help optimizing a function

el_supremo:

Just initializing the array

I don't think so - it accesses an element off the end of the array and does nothing with it. That might be at least part of your problem.

Pete

My mistake. I removed that line and put it in the header file.

#ifndef THERMOCOUPLE_H
#define THERMOCOUPLE_H

#include <Arduino.h>
#include "Nanoshield_Thermocouple.h"
#include "config.h"

class Thermocouple{
  public:
    Thermocouple();
    bool is_stable();
    float temperature();
    void send_serial_data();
    unsigned int time;
    unsigned long timeout;
    unsigned long interval;
  protected:    
    int temp_index;
    float last_readings[recording_time];
    Nanoshield_Thermocouple thermocouple;
};

#endif

The problem still persists though. Does anyone have a better implementation for the max and minimum value of an array functions?