Unofficial response to "PoE Elevator Code"

Original post: https://vexforum.com/t/poe-elevator-code/43729/1

Do you have any pictures of what you are trying to code?

What do you mean you have designed this code at the bottom?
Please “Attach a file” with the full code that is on the robot (if there is more code than what you originally posted)

In the code you posted, when


going <= 100

and


SensorValue[limitSwitchTwo] == 1

and


SensorValue[sonarTwo] == 2

, you check to see if


SensorValue[sonarTwo] == 5

. It can’t be - you just checked that it was equal to 2.

You can use


 code] insert code here (with no spaces inside the square brackets)  /code]

to put your code in nicely. This is the code you posted in your other post on the official tech support channel (I’ve edited it so it has less nesting, and doesn’t do your LED things).


#pragma config(Sensor, dgtl1, limitSwitchOne, sensorTouch)
#pragma config(Sensor, dgtl2, limitSwitchTwo, sensorTouch)
#pragma config(Sensor, dgtl3, limitSwitchThree, sensorTouch)
#pragma config(Sensor, dgtl4, greenOne, sensorLEDtoVCC)
#pragma config(Sensor, dgtl5, greenTwo, sensorLEDtoVCC)
#pragma config(Sensor, dgtl6, greenThree, sensorLEDtoVCC)
#pragma config(Sensor, dgtl7, sonar, sensorSONAR_inch)
#pragma config(Sensor, dgtl9, sonarTwo, sensorSONAR_inch)
#pragma config(Motor, port2, motorOne, tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
//*!!Platform Type: Natural Language PLTW                          !!*//

task main() {
    int ok = 0;
    int going = 0;

    while (true) {
        if (going <= 100 && SensorValue[limitSwitchOne] && SensorValue[sonarTwo] == 5) {
            startMotor(motorOne, 12);
            ok = ok + 1;
            if (SensorValue[sonar] == 5) {
                stopMotor(motorOne);
                // flash leds
                ok = ok - 1;
                going = 0;
            }
            going = going + 1;
        }
        if (going <= 100 && SensorValue[limitSwitchOne] && SensorValue[sonarTwo] == 2) {
            startMotor(motorOne, 12);
            ok = ok + 1;
            if (SensorValue[sonar] == 5) {
                stopMotor(motorOne);
                // flash leds
                ok = ok - 1;
                going = 0;
            }
            going = going + 1;
        }
        if (going <= 100 && SensorValue[limitSwitchTwo] && SensorValue[sonar] == 5) {
            startMotor(motorOne, -12);
            ok = ok + 1;
            if (SensorValue[sonarTwo] == 5) {
                stopMotor(motorOne);
                // flash leds
                ok = ok - 1;
                going = 0;
            }
            going = going + 1;
        }
        if (going <= 100 && SensorValue[limitSwitchTwo] && SensorValue[sonarTwo] == 2) {
            startMotor(motorOne, 12);
            ok = ok + 1;
            if (SensorValue[sonarTwo] == 5) { // THIS WILL NEVER HAPPEN
                stopMotor(motorOne);
                // flash leds
                ok = ok - 1;
                going = 0;
            }
            going = going + 1;
        }
        if (going <= 100 && SensorValue[limitSwitchThree] && SensorValue[sonar] == 5) {
            startMotor(motorOne, -12);
            ok = ok + 1;
            if (SensorValue[sonarTwo] == 2) {
                stopMotor(motorOne);
                // flash leds
                ok = ok - 1;
                going = 0;
            }
            going = going + 1;
        }
        if (going <= 100 && SensorValue[limitSwitchThree] && SensorValue[sonarTwo] == 5) {
            startMotor(motorOne, -12);
            ok = ok + 1;
            if (SensorValue[sonarTwo] == 2) { // THIS WILL NEVER HAPPEN
                stopMotor(motorOne);
                // flash leds
                ok = ok - 1;
                going = 0;
            }
            going = going + 1;
        }
        
        if (going > 100 && ok == 0 && SensorValue[sonarTwo] == 5) {
            startMotor(motorOne, 12);
            if (SensorValue[sonar] == 5) {
                stopMotor(motorOne);
                // flash leds
                going = 0;
            }
        }
        if (going > 100 && ok == 0 && SensorValue[sonarTwo] == 2) {
            startMotor(motorOne, 12);
            if (SensorValue[sonar] == 5) {
                stopMotor(motorOne);
                // flash leds
                going = 0;
            }
        }
        
    } // [end] while(true)
} // [end] task main()