true I just played wth the standard program of debounce to turn on and of a relais.
see code below.
the only thing that I have to add now is that if relaispin 1 = high the other relais have to go off
so relais pin 1 = high and relais pin 2,3,4,5 are off
relais pin 2 = high and relais pin 1,3,4,5 are off.
is that possible?
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin1 = 3; // the number of the pushbutton pin
const int buttonPin2 = 4;
const int buttonPin3 = 5;
const int buttonPin4 = 6;
const int buttonPin5 = 7;
const int relaisPin1 = 8; // the number of the relais pin
const int relaisPin2 = 9;
const int relaisPin3 = 10;
const int relaisPin4 = 11;
const int relaisPin5 = 12;
// Variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int relaisState1 = HIGH; // the current state of the output pin
int relaisState2 = HIGH;
int relaisState3 = HIGH;
int relaisState4 = HIGH;
int relaisState5 = HIGH;
int lastButtonState1 = LOW; // the previous reading from the input pin
int lastButtonState2 = LOW;
int lastButtonState3 = LOW;
int lastButtonState4 = LOW;
int lastButtonState5 = LOW;
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime1 = 0; // the last time the output pin was toggled
long lastDebounceTime2 = 0;
long lastDebounceTime3 = 0;
long lastDebounceTime4 = 0;
long lastDebounceTime5 = 0;
long debounceDelay1 = 50; // the debounce time; increase if the output flickers
long debounceDelay2 = 50;
long debounceDelay3 = 50;
long debounceDelay4 = 50;
long debounceDelay5 = 50;
void setup() {
// initialize the relais pin as an output:
pinMode(relaisPin1, OUTPUT);
pinMode(relaisPin2, OUTPUT);
pinMode(relaisPin3, OUTPUT);
pinMode(relaisPin4, OUTPUT);
pinMode(relaisPin5, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin5, INPUT);
// set initial relais state
digitalWrite(relaisPin1, relaisState1);
digitalWrite(relaisPin2, relaisState2);
digitalWrite(relaisPin3, relaisState3);
digitalWrite(relaisPin4, relaisState4);
digitalWrite(relaisPin5, relaisState5);
}
void loop() {
// read the state of the switch into a local variable:
int reading1 = digitalRead(buttonPin1);
int reading2 = digitalRead(buttonPin2);
int reading3 = digitalRead(buttonPin3);
int reading4 = digitalRead(buttonPin4);
int reading5 = digitalRead(buttonPin5);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading1 != lastButtonState1) {
// reset the debouncing timer
lastDebounceTime1 = millis();
}
if ((millis() - lastDebounceTime1) > debounceDelay1) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading1 != buttonState1) {
buttonState1 = reading1;
// only toggle the LED if the new button state is HIGH
if (buttonState1 == HIGH) {
relaisState1 = !relaisState1;
}
}
}
//222222222222222222222222222222222222222222222222222222222222222222222222222
if (reading2 != lastButtonState2) {
// reset the debouncing timer
lastDebounceTime1 = millis();
}
if ((millis() - lastDebounceTime2) > debounceDelay2) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading2 != buttonState2) {
buttonState2 = reading2;
// only toggle the LED if the new button state is HIGH
if (buttonState2 == HIGH) {
relaisState2 = !relaisState2;
}
}
}
//3333333333333333333333333333333333333333333333333333333333333333333333333
if (reading3 != lastButtonState3) {
// reset the debouncing timer
lastDebounceTime3 = millis();
}
if ((millis() - lastDebounceTime3) > debounceDelay3) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading3 != buttonState3) {
buttonState3 = reading3;
// only toggle the LED if the new button state is HIGH
if (buttonState3 == HIGH) {
relaisState3 = !relaisState3;
}
}
}
//44444444444444444444444444444444444444444444444444444444444444444444444
if (reading4 != lastButtonState4) {
// reset the debouncing timer
lastDebounceTime4 = millis();
}
if ((millis() - lastDebounceTime4) > debounceDelay4) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading4 != buttonState4) {
buttonState4 = reading4;
// only toggle the LED if the new button state is HIGH
if (buttonState4 == HIGH) {
relaisState4 = !relaisState4;
}
}
}
//555555555555555555555555555555555555555555555555555555555555555555555555
if (reading5 != lastButtonState5) {
// reset the debouncing timer
lastDebounceTime5 = millis();
}
if ((millis() - lastDebounceTime5) > debounceDelay5) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading5 != buttonState5) {
buttonState5 = reading5;
// only toggle the LED if the new button state is HIGH
if (buttonState5 == HIGH) {
relaisState5 = !relaisState5;
}
}
}
//------------------------------------------------------------------------
// set the LED:
digitalWrite(relaisPin1, relaisState1);
digitalWrite(relaisPin2, relaisState2);
digitalWrite(relaisPin3, relaisState3);
digitalWrite(relaisPin4, relaisState4);
digitalWrite(relaisPin5, relaisState5);
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState1 = reading1;
lastButtonState2 = reading2;
lastButtonState3 = reading3;
lastButtonState4 = reading4;
lastButtonState5 = reading5;
}