Hello!
I bought my first arduino and i started with my first project, it is almost succesfuly done but i have problem with one thing.
So my project is coming/leaving home module for car. If i lock/unlock car it turns on fog lights for 20 seconds if there is dark outside.
Im taking signal from turn signals (lock/unlock) and other signal from igniton. So if i unlock car and i get behind wheel before 20 seconds are elapsed and i turn on ignition it immediately turns off foglights.
Till here is everything ok, but here is problem. When ignition is on (while driving) it shouldnt turn on the fog lights. What should i do that while ignition is on, module will not turn on fog lights?
Im a bit lost here so i will be very thankful for help!
Here is my code:
#include <elapsedMillis.h>
const int ignition = 2;
const int turnsignal = 13;
const int foglight = 8;
int buttonState = 0;
int sensor = A0;
int sensorValue = 0;
elapsedMillis timer0;
#define interval 20000
boolean timer0Fired;
void setup() {
// put your setup code here, to run once:
pinMode(foglight, OUTPUT);
pinMode(ignition, INPUT);
pinMode(turnsignal, INPUT);
timer0 = 0;
attachInterrupt(digitalPinToInterrupt(2),izklop,HIGH);
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(sensor);
Serial.println(sensorValue);
{
buttonState = digitalRead(turnsignal);
delay(100);
if(sensorValue < 50) //setting a threshold value
if (buttonState == HIGH){
digitalWrite(foglight, HIGH);
timer0Fired = false;
timer0 = 0;
}
if ((!timer0Fired) && (timer0 > interval)) {
timer0Fired = true; // don't execute this again
digitalWrite(foglight, LOW); // turn led off after 5 sec
}
}
}
void izklop(){
digitalWrite(foglight, LOW);
}