I am a newbie to coding and am having difficulty understanding what to code to get the delay to work. I want to replace an anologue emmersion heater controller with a processor (arduino likely). The digital thermocontroller produces a low when temp at set point and a high when below. I have been using a latching push button with 10k pullupresistor on breadboard. When latched low the LED goes off ( pin2 hi) and only comes on after a delay of 5 secs (pin2 Lo) when the pushbutton unlatched to go high through pup res. Have tried using falling / rising edge in code but doesn't make any difference. What do I do to this monostable code to get the loop going through its cycle? The delay is used to reset another controller which requires a 4 second reset time.
const int trigger = 2; //Pin2 as trigger pin. Signal from thermal controller.
const int output = 10; //Pin 10 as Output pin.
int Time = 5000; //Preset time delay.
void setup() {
pinMode(output, OUTPUT);
pinMode(trigger, LOW); // pin stays low until temperature drops below set point then High.
}
If I understand you correctly, you want the loop() to continue looping while the delay is in progress?
If so, you need a millis() based approach. And a variable to keep track of what your code is currently doing; you might want to read up on finite state machine.
Thanks didn't know about the tags, will do in future. The timing doesn't happen because the input pin 2 is held low even if I use a FALLING edge as trigger. The delay starts when the pin goes HIGH, then for the correct delay of 5 secs. In practice on my breadboard, the LED (pin10) is illuminated with a LOW on pin 10 at start up then when the latching pushbutton is pressed the LED goes off and stays off until the button is delatched (pin2 HIGH) and stays off for 5 further seconds then goes on. I can't find any code or instuction that deals with inputs staying HIGH or LOW continuously. At present I use a capacitor/ resistor timing circuit to produce the effect which I am looking to replace with code. Is that useful you?
I'm getting more confused than I possibly already was.
Can you please describe what needs to happen when
1)
the input pin goes low
2)
the input pin stays low for more than 5 seconds
3)
the input pin goes high
4)
the input pin stays high
const int trigger = 2; //Pin2 as trigger pin. Signal from thermal controller.
const int output = 10; //Pin 10 as Output pin.
int Time = 5000; //Preset time delay.
void setup() {
pinMode(output, OUTPUT);
pinMode(trigger, LOW); // pin stays low until temperature drops below set point then High.
}
void loop() {
if (digitalRead(trigger) == LOW) {
digitalWrite(output, HIGH);
delay(Time);
digitalWrite(output, LOW);
}
else {
digitalWrite(output, LOW);
}
}
First, in setup(), did you set 'trigger' to be an input or an output?