I am trying for my first project to digitalWrite several pins high or low with a delay, but the delays are ignored. I used the control relay example and added extra output pins. The result is all three defined pins are going on and off simultaniously instead of with a delay.
/*
* This example shows basic Switch Binary functionality
* Control an external relay on pin 13
*/
// pin number, where relay is connected
#define RELAY_PIN9 9
#define RELAY_PIN10 10
#define RELAY_PIN11 11
// variable to store current relay state
byte lastSetValue;
// next macro sets up the Z-Uno channels
// in this example we set up 1 switch binary channel
// you can read more on http://z-uno.z-wave.me/Reference/ZUNO_SWITCH_BINARY/
ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_BINARY(getter, setter));
void setup() {
pinMode(RELAY_PIN9, OUTPUT); // set up relay pin as output
pinMode(RELAY_PIN10, OUTPUT); // set up relay pin as output
pinMode(RELAY_PIN11, OUTPUT); // set up relay pin as output
}
void loop() {
// loop is empty, because all the control comes over the Z-Wave
}
// function, which returns the previously saved relay value
// this function runs only once the controller asks
byte getter() {
return lastSetValue;
}
// function, which sets new relay state
// this function runs only once the controller sends new value
void setter(byte newValue) {
// newValue is a variable, holding a "value"
// which came from the controller or other Z-Wave device
if (newValue > 0) { // if greater then zero
digitalWrite(RELAY_PIN9, HIGH); //turn relay on
delay(1000);
digitalWrite(RELAY_PIN10, HIGH); //turn relay on
delay(1000);
digitalWrite(RELAY_PIN11, HIGH); //turn relay on
} else { // if equals zero
digitalWrite(RELAY_PIN9, LOW); //turn relay off
delay(1000);
digitalWrite(RELAY_PIN10, LOW); //turn relay off
delay(1000);
digitalWrite(RELAY_PIN11, LOW); //turn relay off
}
// save the new value in a variable
lastSetValue = newValue;
}
Is it possible to create a delay on another way? I tried a lot of possibilities, but i am kinda stuck here.
What i would like to do is opening and closing ports one after another in a sequence.
// pin number, where relay is connected
#define RELAY_PIN9 9
#define RELAY_PIN10 10
#define RELAY_PIN11 11
// variable to store current relay state
byte lastSetValue;
int state; // integer to store the switch value
// next macro sets up the Z-Uno channels
// in this example we set up 1 switch binary channel
// you can read more on http://z-uno.z-wave.me/Reference/ZUNO_SWITCH_BINARY/
ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_BINARY(getter, setter));
void setup() {
pinMode(RELAY_PIN9, OUTPUT); // set up relay pin as output
pinMode(RELAY_PIN10, OUTPUT); // set up relay pin as output
pinMode(RELAY_PIN11, OUTPUT); // set up relay pin as output
}
void loop() {
if (state == 1) { // if state equals 1
digitalWrite(RELAY_PIN10, HIGH); //turn relay on
delay (1000);
digitalWrite(RELAY_PIN11, HIGH); //turn relay off
} else { // if state equal snot 1
digitalWrite(RELAY_PIN10, LOW); //turn relay off
delay (1000);
digitalWrite(RELAY_PIN11, LOW); //turn relay off
}
// loop used for delayed ports
}
// function, which returns the previously saved relay value
// this function runs only once the controller asks
byte getter() {
return lastSetValue;
}
// function, which sets new relay state
// this function runs only once the controller sends new value
void setter(byte newValue) {
// newValue is a variable, holding a "value"
// which came from the controller or other Z-Wave device
if (newValue > 0) { // if greater then zero
digitalWrite(RELAY_PIN9, HIGH); //turn relay on
state = 1;
} else { // if equals zero
digitalWrite(RELAY_PIN9, LOW); //turn relay off
state = 0;
}
// save the new value in a variable
lastSetValue = newValue;
}