Hello, I'm fairly new to all this, basically I am trying to control a garage door opener keeping the hardware more or less the way it is. For this i will have a relay for motor up and down, as well as to control the fan, which will run when the it is at the bottom limit. I've written some simple code and seem to have found a dead end. any help is appreciated!
const int motorUp = 2;
const int motorDown = 3;
const int fanPin = 4;
const int topSwitch = 5;
const int bottomSwitch = 6;
const int switchPin = 7;
void setup() {
// put your setup code here, to run once:
pinMode(motorUp, OUTPUT);
pinMode(motorDown, OUTPUT);
pinMode(fanPin, OUTPUT);
pinMode(topSwitch, INPUT);
pinMode(bottomSwitch, INPUT);
pinMode(switchPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int switchPos = digitalRead(switchPin);
int topLimit = digitalRead(topSwitch);
int bottomLimit = digitalRead(bottomSwitch);
if ((switchPos) == HIGH)
{
Serial.write("button pooshed");
if ((topLimit) == HIGH)
{
digitalWrite(motorDown, HIGH);
if ((bottomLimit) == HIGH)
{
digitalWrite(motorDown, LOW);
}
}
if ((bottomLimit) == HIGH)
{
digitalWrite(motorUp, HIGH);
if ((topLimit) == HIGH)
{
digitalWrite(motorUp, LOW);
}
}
else
{
digitalWrite(motorUp, HIGH);
if ((topLimit) == HIGH)
{
digitalWrite(motorUp, LOW);
}
}
}
if ((bottomLimit) == HIGH)
{
digitalWrite(fanPin, HIGH);
}
else if ((bottomLimit) == LOW)
{
digitalWrite(fanPin, LOW);
}
}