Memory permission error using limit switch

If I remember right this is caused by trying to use the brain’s three wire ports before VexCode actually processes they exist. You can fix it by making a triport on port 22. This is because vexcode treats the three wire ports on the brain like a three wire port expander on the non-existent port 22. Here’s your code modified to do this:

triport ThreeWirePort = triport(PORT22);
motor a (PORT20);
limit b (ThreeWirePort.H);

using namespace vex;

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();
    while(true) {
        if (b.pressing()) {
            a.spin(directionType::fwd, 100, velocityUnits::pct);
        }
        else a.stop();
    }
}
3 Likes