Hello my friend. I write my sketch for my car and i have a problem to read state my button. Sketch i write with millis() and this is problem because i don't understand 100% millis(); Can somebody help me i copy here little my sketch.
int ThermistorPin1 = A0;
int ThermistorPin2 = A1;
int Vo;
float R1 = 10000;
float logR2, R2, T, Temp_water, Temp_exhaust;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
int fan_pin = 3;
int glow_plug_pin = 5;
int fuel_pump_pin = 6;
int push_pin = 13;
float fuel_need;
float glow_time;
float fan_speed;
void setup() {
Serial.begin(9600);
pinMode(fan_pin, OUTPUT);
pinMode(glow_plug_pin, OUTPUT);
pinMode(fuel_pump_pin, OUTPUT);
pinMode(glow_plug_pin, HIGH);
pinMode(fuel_pump_pin, HIGH);
pinMode(push_pin, INPUT_PULLUP);
pinMode(A0, INPUT);
pinMode(A5, INPUT);
}
void loop() {
webasto_control();
temp_control();
fuel_pump();
fan();
glow_plug();
}
void webasto_control() {
static unsigned long timer;
if (millis() < timer) {
timer = millis();
}
int reading = digitalRead(push_pin);
if(reading == LOW){
if (millis() > timer + 500) {
fuel_need = 0; // Here I need: when state button is LOW and Temp_exhaust > 20 do:
fan_speed = 100; fuel_need = 0; fan_speed = 100; glow_time = 0;
glow_time = 0;
}
}
if(reading == HIGH){
fuel_need = 0; // Here i need when state button is HIGH start my program.
fan_speed = 0;
glow_time = 0;
}
if (millis() > timer + 500) {
fuel_need = 0;
fan_speed = 100;
glow_time = 0;
}
if (millis() > timer + 3500) {
fuel_need = 0;
fan_speed = 0;
glow_time = 0;
if (millis() > timer + 30000 && Temp_water > 0 && Temp_exhaust > 45) {
glow_time = 0;
fuel_need = 90;
fan_speed = 70;
}
if (millis() > timer + 45000 && Temp_exhaust < 25) {
glow_time = 0;
fuel_need = 0;
fan_speed = 0;
}