Logical NOT operator

  1. 7 weeks ago

    sabarrett328

    Nov 27 Grand Blanc, MI 46838C Major Trouble

    (originally posted in non-public section)

    Is there a logical NOT operator in robotC? I looked around and I can't see one referenced (web searches... I don't have robotC with me at work right now). My team wants to make an indicator light on their robot follow the state of a switch, and since the lights are on when the output is off, having a not operator would make this simple.

    I was hoping for a "teaching moment" in programming about logic, boolean values, etc with this.

    Wanting to do something like...

    sensorvalue(LEDoutput) = !sensorvalue(switchinput)

    I realize this isn't correct, but that was what I was thinking of... :-)

  2. DaOctoOw

    Nov 27 79298d

    Try:

    if(sensorValue(swichinput) != 1){
    sensorValue(LEDoutput) == 1;
    }
  3. Andrew Strauss

    Nov 27 Ontario, Canada 5225A Mentor

    The code you provided (SensorValue[LEDOutput] = !SensorValue[switchInput]) should work. The operator ! acts as a logical not in C, and for the most part, RobotC mimics C in terms of operators.

  4. Joey The Great

    Nov 27 Suspended Maryland 24k

    or you could say
    if(sensorValue(switchinput) == 0){
    //code here
    }
    because the switches only have two values.

  5. sabarrett328

    Nov 27 Grand Blanc, MI 46838C Major Trouble

    I'll give it a try when I get back home. The girls this year are new to coding something like this, and the last time I wrote something in C was in 91, so I'm kinda rusty myself. I've been posing the things they want to do more as exercises with a starting framework, but not actual code, so they have to get the code right, the configuration right and integrate it into their program. I'll figure it out myself ahead of time so I can help them through troubleshooting and questions. They are getting better, but logical operators are not something they've really done before.

 

or Sign Up to reply!