Limit Switch problem

We’re trying to program a digital input with a limit switch. How do we set the if statement?

This is what we have so far


if(Clamplimit -> Get() > 0)
{
       s[0] -> Set(false);
       s[1] -> Set(true);
}

Is it correct?

How you write the if statement depends on what you want it to do.

What do you want it to do?

We have a claw connected to solenoids 7 and 6. We want the limit switch to close the claw when it’s hit

You just need to turn


if (limit_switch_active)
{
    activate_solenoid_6;
    activate_solenoid_7;
}

into real code that compiles.

Replace limit_switch_active with whatever it takes to read your limit switch. That’s something like Clamplimit->Get(), right? Replace the activate_solenoid_# with whatever it takes to put your solenoids in the desired state. I don’t know how you’ve instantiated your limit switch or your solenoids, and I don’t know how they are wired, so I can’t give you working code to copy and paste.

I assume you’ll want some way to open the claw later, right?

This is how we have it set up


DigitalInput *Clamplimit;     //Limit Switch for clamp

Clamplimit = new DigitalInput(2); //Limit Switch for clamp (Digital Input)

if(Clamplimit)
{
       s[6] -> Set(false);
       s[7] -> Set(true);
}

Will this work as is?

No, it needs to be:


DigitalInput *Clamplimit;     //Limit Switch for clamp

Clamplimit = new DigitalInput(2); //Limit Switch for clamp (Digital Input)

if(Clamplimit->Get())
{
       s[6] -> Set(false);
       s[7] -> Set(true);
}

Also, what class is s an instance of?