Jet turbine control unit (ECU) - Arduino (Coding guidance - SORTED)

Arduino code, operational but not optimal :wink:

// Setup LCD
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 7, d5 = 6, d6 = 5, d7 = 4;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// Setup temperature sensor MAX6675 and Pin 8,9,10
#include “max6675.h”
int ktcSO = 8;
int ktcCS = 9;
int ktcCLK = 10;
MAX6675 ktc(ktcCLK, ktcCS, ktcSO);

// Setup of RPM sensing using Hall sensor U1881 and a 10k resistor
volatile byte half_revolutions;
unsigned int rpm;
unsigned long timeold;

// RPM
void rpm_fun()
{
half_revolutions++;

}
void magnet_detect()//This function is called whenever a magnet/interrupt is detected by the arduino
{
half_revolutions++;
}

void setup() {
Serial.begin(115200);
attachInterrupt(0, magnet_detect, RISING); //Initialize the intterrupt pin (Arduino digital pin 2);
half_revolutions = 0;
rpm = 0;
timeold = 0;
lcd.clear();
lcd.begin(16, 2);
}

void loop()
{
rpm = 30*1000/(millis() - timeold)2half_revolutions;
timeold = millis();
half_revolutions = 0;
lcd.setCursor(0, 1);
lcd.print(“EGT”);
lcd.setCursor(4, 1);
lcd.print(ktc.readCelsius(), 0); // 0 = No decimal points.
lcd.setCursor(0, 0);
lcd.print(“RPM”);
lcd.setCursor(4, 0);
lcd.print(rpm);
delay(250);
lcd.clear();
}