Jump to content

Arduino Logic Question

cluelessgenius

ok so im trying throw together a remote control for a wheel chair lift at my parents house without any specific knowledge about arduino BUT 

even still i have figured out how to read the values off of the 433mhz transmitters and also how to close the relays BUT

i can only allow one of 2 relays to be open at a time and it can oinly be open as long as the keyfob is pressed BUT

somehow my rudamentary code that i pasted together always shuts off both relays immediatly after opening them.

 

and im not that trained in thinking in a constant loop of code id love some help here

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();
const int Relay1Pin = 7;
const int Relay2Pin = 8;
const int UpSignal = 24433;
const int DownSignal = 26120;
int actualSignal = 0;
 
void setup() 
{
  pinMode(Relay1Pin, OUTPUT);
  pinMode(Relay2Pin, OUTPUT);
  
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Empfänger ist an Interrupt-Pin "0" - Das ist am UNO der Pin2
}

void loop() {
  actualSignal = 0;
  if (mySwitch.available()) // Wenn ein Code Empfangen wird...
  {
    int value = mySwitch.getReceivedValue(); // Empfangene Daten werden unter der Variable "value" gespeichert.
  
    if (value == 0) // Wenn die Empfangenen Daten "0" sind, wird "Unbekannter Code" angezeigt.
    {
      Serial.println("Unbekannter Code");
    } 
    else // Wenn der Empfangene Code brauchbar ist, wird er hier an den Serial Monitor gesendet.
    {
      Serial.print("Empfangen: ");
      actualSignal = mySwitch.getReceivedValue();
      Serial.println( actualSignal );
    }
    mySwitch.resetAvailable(); // Hier wird der Empfänger "resettet"
  }
  if(actualSignal==UpSignal)
  {
    digitalWrite(Relay2Pin, LOW);
    Serial.println( "Relay2Pin LOW" );
    //delay(1000);
    digitalWrite(Relay1Pin, HIGH);
    Serial.println( "Relay1Pin HIGH" );
  }
  else if(actualSignal==DownSignal)
  {
    digitalWrite(Relay1Pin, LOW);
    Serial.println( "Relay1Pin LOW" );
    //delay(1000);
    digitalWrite(Relay2Pin, HIGH);
    Serial.println( "Relay2Pin HIGH" );
  }
  else if((digitalRead(Relay1Pin)==HIGH || digitalRead(Relay2Pin)==HIGH) && actualSignal!=UpSignal && actualSignal!=DownSignal)
  {
      Serial.print("Empfangen: ");
      Serial.println( actualSignal );
    digitalWrite(Relay1Pin, LOW);
    Serial.println( "Relay1Pin LOW" );
    digitalWrite(Relay2Pin, LOW);
    Serial.println( "Relay2Pin LOW" );
  }
}

 

"You know it'll clock down as soon as it hits 40°C, right?" - "Yeah ... but it doesnt hit 40°C ... ever  😄"

 

GPU: MSI GTX1080 Ti Aero @ 2 GHz (watercooled) CPU: Ryzen 5600X (watercooled) RAM: 32GB 3600Mhz Corsair LPX MB: Gigabyte B550i PSU: Corsair SF750 Case: Hyte Revolt 3

 

Link to comment
Share on other sites

Link to post
Share on other sites

What you need is a while.. do loop for the button press. While <button is pressed>, do<activate corresponding relay>. You may need the loop twice (separate for each button).

 

HTH!

"You don't need eyes to see, you need vision"

 

(Faithless, 'Reverence' from the 1996 Reverence album)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×