so im trying to make if statement on a project where an stepper and an 1602 i2c lcd and an temp sensor and an potentometer is used the potentometer controlls the speed of the stepper but to keep updating the screen to showe the temp and the potentometer data slows down the stepper ALOT takes to long to ud update in every loop so what i want is to only update the lcd if temp change or the potentometer data changes
PS. im an beginner in programming stil got a shit load to learn.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <math.h>
#include <AccelStepper.h>
#define ThermistorPIN 0
int tempset;
int temppot = 1;
int potpinfeed = 3;
int feedrate;
AccelStepper stepper(1, 9, 6);
float vcc = 4.81; // only used for display purposes, if used // set to the measured Vcc.
float pad = 9850; // balance/pad resistor value, set this to // the measured resistance of your pad resistor
float thermr = 10000; // thermistor nominal resistanc
float Thermistor(int RawADC) {
long Resistance;
float Temp; // Dual-Purpose variable to save space.
Resistance=pad*((1024.0 / RawADC) - 1);
Temp = log(Resistance); // Saving the Log(resistance) so not to calculate it 4 times later
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 227.75; // Convert Kelvin to Celsius
return Temp; // Return the Temperature
}
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(" starting ");
lcd.setCursor(0,1);
lcd.print("filament extrude");
delay(1000);
Serial.begin(9600);
stepper.setMaxSpeed(1000);
stepper.setSpeed(400);
lcd.clear();
lcd.print("Temp :");
//lcd.print(temp,0);
lcd.print("/");
lcd.print(tempset);
}
void loop()
{
stepper.runSpeed();
float temp;
temp=Thermistor(analogRead(ThermistorPIN));
tempset = analogRead(temppot); // reads the value of the potentiometer (value between 0 and 1023)
tempset = map(tempset, 0, 1023, 0, 290);
//delay(3000);
if ((tempset ) && (tempset ))
{
lcd.clear();
lcd.print("Temp :");
lcd.print(temp,0);
lcd.print("/");
lcd.print(tempset);
{
}
}
else
{
stepper.runSpeed();
}
}