Hi all,
I have some experience with Arduino, but only small programs, and i rarely use seperate functions.
At the moment i am working on a simple program to open and close the door for the chickencoop depending on the light outside.
I have a problem with two Boolean values, i have Googled my but off but i can't seem to find the correct anwers. (probably because i am asking the wrong questions...).
The problem i have is with two buttons, these buttons get activated when the door is either up or down.
I have written a small function to check the buttons and set the Boolean values to True of False (and turn a LED on or off).
-- void checkButton()
But back in the "void loop()" these settings are not copied.'
I understand that a "void()" does not return a value, but i can't seem to find a solution for this problem.
I hope i explained my problem correctly, below i will paste a small part of the code involved.
Thank you for any help you can give me.
bool doorOpen = false; // Set booleans for door open or closed state
bool doorClosed = false;
void loop() {
Other code.....
if (doorError == false) { //As long as there is no problem with the door, see if it is up or down and turn on the correct LED
Serial.println("DoorError = False");
checkDoor();
}
void checkDoor() {
doorUpState = digitalRead(doorUp);
if(doorUpState == HIGH) { // If the door is open turn on the red LED
digitalWrite(redLed, HIGH);
doorOpen = true;
}
doorUpState = digitalRead(doorUp);
if(doorUpState == LOW) { // If the door is not open, turn off the red LED
digitalWrite(redLed, LOW);
doorOpen = false;
}
doorDownState = digitalRead(doorDown);
if(doorDownState == HIGH) { // If the door is down, turn on the green LED
digitalWrite(greenLed, HIGH);
doorClosed = true;
}
doorDownState = digitalRead(doorDown);
if(doorDownState == LOW) { // If the door is not down, turn off the green LED
digitalWrite(greenLed, LOW);
doorClosed = false;
}