Hi guys, sorry if i opened an allready existing topic. I'm trying to make a controll unit for a car dome light. I'm currently using this code for fading on and off when i press it
const int buttonPin = 7;
const int ledPin = 11;
const int fadingDelay = 50;
int buttonState = 0;
boolean fadingState = false;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
if (fadingState == false) {
for (int i = 0; i <= 255; i += 5) {
analogWrite(ledPin, i);
delay(fadingDelay);
}
} else {
for (int i = 255; i >= 0; i -= 5) {
analogWrite(ledPin, i);
delay(fadingDelay);
}
}
fadingState = !fadingState;
}
}
It works fine for turning it on and off but i want to add some extra functions like fading in when i open the door and fading out after some time (~30s), fading in when i unlock the car and fading off when i lock it (i can get a signal from the ECU for this) and fading in when i turn off the ignition.
The original ECU functions for the dome light are, solid on when i open the door or unlock the car (no fade), delay 30 sec and fade out when i close the door, fade out with no delay then i turn the ignition on and it turns straight off with no fade when i lock the car. When i press it it turns on and off with no fade.
Can someone please give me some advice on how i could add those functions?
Thank you
(forgot to mention my ECU turns off after 10min after i lock my car)