Creating Libraries from sketches?

I guess your project has an obstacle sensor of some sort. You could insert a sensor read inside the for loop in Accel and DeAccel functions, righe before or after the delay() call. That line would read like this (pseudocode)

if (obstacle detected) {
stopMotor
}

HTH