int OBSTACLE = 0;
void check_sensors() {
    while(1) {
        //if left sensor pressed, reverse and use the left motor to turn
        if(digital(10) && !OBSTACLE) {
            OBSTACLE=1;
            motor(1,-50);
            motor(3,-50);
            sleep(0.5);
            motor(1,50);
            sleep(0.6);
            OBSTACLE=0;
        }
        //if right sensor pressed, reverse and use the right motor to turn
        else if(digital(11) && !OBSTACLE) {
            OBSTACLE=1;
            motor(1,-50);
            motor(3,-50);
            sleep(0.5);
            motor(3,50);
            sleep(0.6);
            OBSTACLE=0;
        }
    }
}

void move_forward() {
    while(1) {
        //check semaphore
        if(!OBSTACLE) {
            //drive forward
            motor(1,50);
            motor(3,50);
        }
    }
}

int main() {
    //variable initialization
    int movePid, checkPid;
    
    // wait for user to begin
    while(!start_button());
    tone(1000.0,1.0);
    //    process_priority[pid]=2;
    movePid = start_process(move_forward());
    //    process_priority[pid]=1;
    checkPid = start_process(check_sensors());
    //    start_process(prioritize());
    //loop until user presses stop
    while(!stop_button());
    //sleep(2.0);
    
    // Kill Processes
    kill_process( movePid );
    kill_process( checkPid );
    
    //turn off motors to prepare for program termination
    off(1);
    off(3);
    return 0;
}
