Thank you for your reply. Here is my complete code. Im a starter so I made a lot of unnecessary steps.
I used float because I'm calculating with significant numbers, and i didn't get it work with unsigned long.
What do you mean with ISR?
part 1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int XPin=A1;
int YPin=A0;
int resetPin=10;
int contact=9;
int contactstatus= HIGH;
int lastcontactState=LOW;
unsigned long millisreset;
int reseter;
int xreading;
int yreading;
int menuCounter = 1;
int menupState = HIGH;
int lastmenupState=LOW;
int menumState = HIGH;
int lastmenumState=LOW;
int eenheidCounter = 1;
int eenheidpState = HIGH;
int lasteenheidpState=LOW;
int eenheidmState = HIGH;
int lasteenheidmState=LOW;
volatile float rpmHV;
volatile float flowHV;
volatile float rpmTRV;
volatile float flowTRV;
volatile float rpmTAV;
volatile float flowTAV;
unsigned long millisstilstand;
int stilstandmillisA=1500;
int stilstand;
int HVmillis;
unsigned long millishv;
float RPMAFSTAND= 1.5625;
float totaldistance=0;
float tankinhoud= 35.0;
float stationair=0;
float HKL;
float HLK;
float TVKL;
float TVLK;
float TVL;
float GTVKL;
float GTVLK;
float OVKL;
float OVLK;
float OVL;
float ARK;
void setup()
{
lcd.init();
pinMode(resetPin, INPUT);
pinMode(contact, INPUT);
attachInterrupt(1, rpm_fun, LOW);
rpmHV = 0;
rpmTRV = 0;
rpmTAV = 0;
attachInterrupt(0, flow_fun, RISING);
flowHV= 0;
flowTRV= 0;
flowTAV= 0;
Serial.begin(9600);
}
void loop(){
beeldscherm();
menuteller();
eenheidteller();
verbruik();
stilstaan();
reset();
contactvoorwaarden();
}
void contactvoorwaarden(){
contactstatus= digitalRead(contact);
if (contactstatus!= lastcontactState){
if (contactstatus==HIGH){
lcd.backlight();
lcd.display();
lcd.clear();
menuCounter=16;
}
else{
lcd.noBacklight();
lcd.noDisplay();
}}
lastcontactState =contactstatus;
}
void reset(){
reseter=digitalRead(resetPin);
if (reseter==HIGH){
millisreset = millis() + 3000;
}
if ((long)(millis()-millisreset)>=0 && reseter==LOW){
lcd.clear();
menuCounter=10;
}
}
void menuteller(){
xreading=analogRead(XPin);
if(xreading > 600){
menupState=HIGH;
}
else{
menupState=LOW;
}
if(xreading < 434){
menumState=HIGH;
}
else{
menumState=LOW;
}
if (menupState != lastmenupState ) {
if (menupState == HIGH) {
menuCounter--;
lcd.clear();
}
}
lastmenupState= menupState;
if (menumState != lastmenumState ) {
if (menumState == HIGH) {
menuCounter++;
lcd.clear();
}
}
lastmenumState= menumState;
}
void eenheidteller(){
yreading=analogRead(YPin);
if(yreading > 600){
eenheidpState=HIGH;
}
else{
eenheidpState=LOW;
}
if(yreading < 434){
eenheidmState=HIGH;
}
else{
eenheidmState=LOW;
}
if (eenheidpState != lasteenheidpState ) {
if (eenheidpState == HIGH) {
eenheidCounter--;
lcd.clear();
}
}
lasteenheidpState= eenheidpState;
if (eenheidmState != lasteenheidmState ) {
if (eenheidmState == HIGH) {
eenheidCounter++;
lcd.clear();
}
}
lasteenheidmState= eenheidmState;
}
void beeldscherm(){
if (menuCounter == 0){
menuCounter = 5;
}
else if (menuCounter == 1){
if (rpmHV==0){
lcd.setCursor(0,0);
lcd.print("actueel verbruik");
lcd.setCursor(7,1);
lcd.print("liter/uur");
lcd.setCursor(0,1);
lcd.print(stationair,1);
lcd.print(" ");
}
else if (eenheidCounter ==1){
lcd.setCursor(0,0);
lcd.print("actueel verbruik");
lcd.setCursor(7,1);
lcd.print(" km/L");
lcd.setCursor(0,1);
lcd.print(HKL,1);
lcd.print(" ");
}
else if (eenheidCounter ==2){
lcd.setCursor(0,0);
lcd.print("actueel verbruik");
lcd.setCursor(7,1);
lcd.print(" L/100km");
lcd.setCursor(0,1);
lcd.print(HLK,1);
lcd.print(" ");
}
else if (eenheidCounter >=3){
eenheidCounter =1;
}
else if (eenheidCounter ==0){
eenheidCounter = 2;
}
}
else if (menuCounter == 2){
if (eenheidCounter ==1){
lcd.setCursor(3,0);
lcd.print("verbruik trip");
lcd.setCursor(12,1);
lcd.print("km/L");
lcd.setCursor(0,1);
lcd.print(TVKL,1);
lcd.print(" ");
}
else if (eenheidCounter ==2){
lcd.setCursor(3,0);
lcd.print("verbruik trip");
lcd.setCursor(9,1);
lcd.print("L/100km");
lcd.setCursor(0,1);
lcd.print(TVLK,1);
lcd.print(" ");
}
else if (eenheidCounter ==3){
lcd.setCursor(3,0);
lcd.print("verbruik trip");
lcd.setCursor(11,1);
lcd.print("Liter");
lcd.setCursor(0,1);
lcd.print(TVL,1);
lcd.print(" ");
}
else if (eenheidCounter >=4){
eenheidCounter =1;
}
else if (eenheidCounter ==0){
eenheidCounter = 3;
}
}
else if (menuCounter == 3){
if (eenheidCounter ==1){
lcd.setCursor(3,0);
lcd.print("verbruik tank");
lcd.setCursor(12,1);
lcd.print("km/L");
lcd.setCursor(0,1);
lcd.print(GTVKL,1);
lcd.print(" ");
}
else if (eenheidCounter ==2){
lcd.setCursor(3,0);
lcd.print("verbruik tank");
lcd.setCursor(9,1);
lcd.print("L/100km");
lcd.setCursor(0,1);
lcd.print(GTVLK,1);
lcd.print(" ");
}
else if (eenheidCounter >=3){
eenheidCounter =1;
}
if (eenheidCounter ==0){
eenheidCounter = 2;
}
}
else if (menuCounter == 4){
if (eenheidCounter ==1){
lcd.setCursor(0,0);
lcd.print("overall verbruik");
lcd.setCursor(12,1);
lcd.print("km/L");
lcd.setCursor(0,1);
lcd.print(OVKL,0);
lcd.print(" ");
}
else if (eenheidCounter ==2){
lcd.setCursor(0,0);
lcd.print("overall verbruik");
lcd.setCursor(9,1);
lcd.print("L/100km");
lcd.setCursor(0,1);
lcd.print(OVLK,0);
lcd.print(" ");
}
else if (eenheidCounter ==3){
lcd.setCursor(0,0);
lcd.print("overall verbruik");
lcd.setCursor(11,1);
lcd.print("Liter");
lcd.setCursor(0,1);
lcd.print(OVL,0);
lcd.print(" ");
}
else if (eenheidCounter >=4){
eenheidCounter =1;
}
else if (eenheidCounter ==0){
eenheidCounter = 3;
}
}
else if (menuCounter == 5){
lcd.setCursor(5,0);
lcd.print("actieradius");
lcd.setCursor(14,1);
lcd.print("km");
lcd.setCursor(0,1);
lcd.print(ARK,1);
lcd.print(" ");
}