I'm having an issue writing a relatively ambitious piece of code. I need to read multiple thermistors, and update a display every few seconds with the name and temperature of a given sensor. Then, if any of the thermistors read above or below a certain range for 20 seconds, it will turn off a relay and display the name of the sensor which triggered it. The code is far from complete, but I'm at something of a standstill. I know the logical tree I want the code to follow, I'm just not sure what tools I need to manage the sensors and display values. Thanks in advance for any advice/resources. I know pointers might be a solution but I couldn't find anything that didn't explain them with the most abstracted examples possible.
#include <neotimer.h>
#include <SmoothThermistor.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
SmoothThermistor tBed(23);
SmoothThermistor tHotend(24);
SmoothThermistor tAmbient(25);
SmoothThermistor tPSU(26);
Neotimer OLEDtimer = Neotimer(3000);
Neotimer overTimer = Neotimer(200000);
Neotimer tempTimer = Neotimer(35);
//initilization constants for thermistors
#define REFERENCE_RESISTANCE 10000
#define NOMINAL_RESISTANCE 100000
#define NOMINAL_TEMPERATURE 25
#define B_VALUE 3950
int tempArray[4]; //holds current temperature values
int thermArray[4] = {23,24,25,26}; //holds pin values for 4 thermistors
int maxArray[4] = {120,300,80,90}; //max temps for bed, hotend, ambient, and PSU respectively
#define relayPin 2
int sensorSwitch = 1 //cycles once per update of the displau, to change the sensor temp that's displayed
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3D);
smoothThermistor.useAREF(true);
//initialize and turn on relay
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);
}
void loop() {
//short timer used so as not to read the ADC too fast
if(tempTimer.repeat(35)){
updateTemp();
// here is where I'm not sure how to switch between sensors without a for loop, which would be too fast for the adc
}
}
//updtates the display every 3.5 sec
if(OLEDtimer.repeat(3500)){
drawDisplay();
//here i'm also not sure how to pass the name of the current sensor that needs to be displayed to the display function
}
for(int i=1; i<= 4; i++){
if (tempArray[i] < maxArray[i])
overTemp(thermArray[i]);
}
}
void updateTemp(int sensor){
tempArray[sensor] = thermArray[sensor].temperature
//here I'm not sure if I'm allowed to pass the pin number straight to the "temperature" function of the smoothThermistor library
}
void drawDisplay(int temp){
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(10,0);
display.clearDisplay();
display.println("Temp = ");
display.print(temp);
display.display();
}
void overTemp(int sensor)
while (sensor).temperature > ???) // how do I get which overtemperature value I'm supposed to be comparing against based on the sensor I'm reading?