Hi everyone i hope this finds you all well. I am making a controller for my jeep rear door as the body control module has failed. The sequence is this. lift the door handle and the window drops out of the seal. Delay 500 then the latch fires and the tailgate can be opened . Now close the door and a switch in the latch activates to close the window again. Simple timed relays. Now here is my problem ... when the tailgate closes and the microswitch is engaged it Stays engaged so the window close relay keeps restarting its timed period. I need to make it a one shot switch. Delay is no good as it would stop the program from opening the door again and anyway it cant be long enough. I have tried "while" but same problem. I think the answer might be state change but i cant figure it out .. any help would be gratefully appreciated. Iv attached my sample sketch for leds read relays and my delays are long just for debugging.Thank you.
// constants won't change. They're used here to set pin numbers:
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int led_RED = 13; // the number of the LED pin
const int led_GREEN = 12;
const int led_YELLOW = 11;
// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(led_RED, OUTPUT);
pinMode(led_GREEN, OUTPUT);
pinMode(led_YELLOW, OUTPUT);// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState1 == HIGH) {
// turn LED on:
digitalWrite(led_RED, HIGH);
delay(2000);
digitalWrite(led_RED, LOW);
digitalWrite(led_GREEN, HIGH);
delay(2000);
digitalWrite(led_GREEN, LOW);
delay(5000);
}
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState2 == HIGH) {
// turn LED on:
digitalWrite(led_YELLOW, HIGH);
delay(2000);
digitalWrite(led_YELLOW, LOW);
}
}