Challenge

Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear

#include 

// Define the states of the finite state machine
typedef enum {
    GEAR_UP,
    GEAR_DOWN,
    GEAR_MOVING
} GearState;

// Define the inputs to the finite state machine
typedef enum {
    GEAR_SWITCH_UP,
    GEAR_SWITCH_DOWN,
    GEAR_POSITION_UP,
    GEAR_POSITION_DOWN
} GearInput;

int main() {
    // Set initial state of the landing gear to down
    GearState currentState = GEAR_DOWN;

    // Loop to read inputs and transition state accordingly
    while (1) {
        GearInput input;
        // Read input from switches and sensors
        // ...

        switch (currentState) {
            case GEAR_UP:
                if (input == GEAR_SWITCH_DOWN) {
                    // Move gear to down position
                    // ...
                    currentState = GEAR_MOVING;
                }
                break;
            case GEAR_DOWN:
                if (input == GEAR_SWITCH_UP) {
                    // Move gear to up position
                    // ...
                    currentState = GEAR_MOVING;
                }
                break;
            case GEAR_MOVING:
                if (input == GEAR_POSITION_UP) {
                    currentState = GEAR_UP;
                } else if (input == GEAR_POSITION_DOWN) {
                    currentState = GEAR_DOWN;
                }
                break;
        }
    }

    return 0;
}
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.