gradually increasing the speed of a dc motor

I'm building a BB-8 droid, and need the DC motors to gradually ramp up to full speed, then gradually return to zero speed upon release of button. This will be controlled by a bluetooth program on my android phone. i need the motor to ramp up, then hold at max speed while the forward button is pressed continually, then ramp back to zero once i release the button on the phone. I tried integrating the code from the demo program, which raps up and down, but it either ramps up then stops, or will not shut off when i release the key.

here is the original code that controls the arduino uno, but the motors go immediately to full power upon key press.

#include "DualMC33926MotorShield.h"
DualMC33926M/otorShield md;
/*
#include <Servo.h>
Servo myservo;
*/

char dataIn = 'S';
char determinant;
char det;
int vel = 200; //Bluetooth Stuff

int overdrive = 13; //Press Toggle Switch #1, the pin13 LED will light up

void setup() {
Serial.begin(9600); 
Serial.println("Dual MC33926 Motor Shield");
md.init();

/*
 myservo.attach(6);delay(100);
 myservo.write(90);delay(100);
*/

}

void loop() {
det = check();  // You'll need to reconstruct this if your not using the Pololu Dual VNH5019

while (det == 'F')   // F, move forward
{
 md.setSpeeds(vel, vel);
 det = check();
}

while (det == 'B')   // B, move back
{
 md.setSpeeds(-vel, -vel);
 det = check();
}

while (det == 'L')   // L, move wheels left
{
 md.setSpeeds(-vel, vel);
 det = check();
}

while (det == 'R')   // R, move wheels right
{
 md.setSpeeds(vel, -vel);
 det = check();
}

while (det == 'I')   // I, turn right forward
{
 md.setSpeeds(vel, vel / 2);
 det = check();
}

while (det == 'J')   // J, turn right back
{
 md.setSpeeds(-vel, -vel / 2);
 det = check();
}

while (det == 'G')   // G, turn left forward
{
 md.setSpeeds(vel /2, vel);
 det = check();
}

while (det == 'H')   // H, turn left back
{
 md.setSpeeds(-vel /2, -vel);
 det = check();
}

while (det == 'S')   // S, stop
{
 md.setSpeeds(0, 0);
 det = check();
}

//---------------------Toggle switch code------------------//
/*while (det == 'W'){myservo.write(180);delay(100);det = check();}
 while (det == 'w'){myservo.write(90);delay(100);det = check();}

 while (det == 'U'){myservo.write(0);delay(100);det = check();}
 while (det == 'u'){myservo.write(90);delay(100);det = check();}
*/

}

int check()
{ if (Serial.available() > 0) {
 dataIn = Serial.read();
 if (dataIn == 'F') {
   determinant = 'F';
 }
 else if (dataIn == 'B') {
   determinant = 'B';
 } else if (dataIn == 'L') {
   determinant = 'L';
 }
 else if (dataIn == 'R') {
   determinant = 'R';
 } else if (dataIn == 'I') {
   determinant = 'I';
 }
 else if (dataIn == 'J') {
   determinant = 'J';
 } else if (dataIn == 'G') {
   determinant = 'G';
 }
 else if (dataIn == 'H') {
   determinant = 'H';
 } else if (dataIn == 'S') {
   determinant = 'S';
 }
 else if (dataIn == '0') {
   vel = 400;
 } else if (dataIn == '1') {
   vel = 380;
 }
 else if (dataIn == '2') {
   vel = 340;
 } else if (dataIn == '3') {
   vel = 320;
 }
 else if (dataIn == '4') {
   vel = 280;
 } else if (dataIn == '5') {
   vel = 240;
 }
 else if (dataIn == '6') {
   vel = 200;
 } else if (dataIn == '7') {
   vel = 160;
 }
 else if (dataIn == '8') {
   vel = 120;
 } else if (dataIn == '9') {
   vel = 80;
 }
 else if (dataIn == 'q') {
   vel = 40;
 }
 else if (dataIn == 'U') {
   determinant = 'U';
 } else if (dataIn == 'u') {
   determinant = 'u';
 }
 else if (dataIn == 'W') {
   determinant = 'W';
 } else if (dataIn == 'w') {
   determinant = 'w';
 }

} return determinant;
}

here is the code from the demo program that ramps the motor up and back down. as i said i have been unable to integrate this into the program that is controlled by the bluetooth program on my phone.

#include "DualMC33926MotorShield.h"

DualMC33926MotorShield md;

void stopIfFault()
{
if (md.getFault())
{
 Serial.println("fault");
 while(1);
}
}

void setup()
{
Serial.begin(115200);
Serial.println("Dual MC33926 Motor Shield");
md.init();
}

void loop()
{
for (int i = 0; i <= 400; i++)
{
 md.setM1Speed(i);
 stopIfFault();
 if (abs(i)%200 == 100)
 {
   Serial.print("M1 current: ");
   Serial.println(md.getM1CurrentMilliamps());
 }
 delay(2);
}

for (int i = 400; i >= -400; i--)
{
 md.setM1Speed(i);
 stopIfFault();
 if (abs(i)%200 == 100)
 {
   Serial.print("M1 current: ");
   Serial.println(md.getM1CurrentMilliamps());
 }
 delay(2);
}

for (int i = -400; i <= 0; i++)
{
 md.setM1Speed(i);
 stopIfFault();
 if (abs(i)%200 == 100)
 {
   Serial.print("M1 current: ");
   Serial.println(md.getM1CurrentMilliamps());
 }
 delay(2);
}

for (int i = 0; i <= 400; i++)
{
 md.setM2Speed(i);
 stopIfFault();
 if (abs(i)%200 == 100)
 {
   Serial.print("M2 current: ");
   Serial.println(md.getM2CurrentMilliamps());
 }
 delay(2);
}

for (int i = 400; i >= -400; i--)
{
 md.setM2Speed(i);
 stopIfFault();
 if (abs(i)%200 == 100)
 {
   Serial.print("M2 current: ");
   Serial.println(md.getM2CurrentMilliamps());
 }
 delay(2);
}

for (int i = -400; i <= 0; i++)
{
 md.setM2Speed(i);
 stopIfFault();
 if (abs(i)%200 == 100)
 {
   Serial.print("M2 current: ");
   Serial.println(md.getM2CurrentMilliamps());
 }
 delay(2);
}
}

Any help would be greatly appreciated. im new to programming, and im afraid this is a little over my head.

[/code]
[/code]

// please edit your posting to use code tags like this, via the </> button

sorry about that...fixed

The example ramp code is blocking (it calls delay()) so its no use to you. You need non-blocking code to
manage the ramping so you can continue to read the bluetooth input.

This means first studying how the BlinkWithoutDelay example sketch works to handle
time-dependent actions without blocking.