LCD Keypad Shield Controlling Motor Speed And Direction

Tell me what you think, This should work for a good deal of brushed esc’s.
Its my first program, and I have a real use for it. Hope someone else can make use of it too.
This uses the LCDKeypad library.

/*
  LCD KEYPAD SHIELD ESC/SERVO CONTROLLER
  Sends signals to an ESC controlling a dc motor, allowing for variable speed and shaft rotation.
  Written by Charles P Clements  
  Many thanks to septillion of Arduino.cc
  Free to use, and distribute.
  Please repost any major changes or additions to the Arduino.cc forum.

            The circuit
   LCD RS pin to digital pin 8
   LCD Enable pin to digital pin 9
   LCD D4 pin to digital pin 4
   LCD D5 pin to digital pin 5
   LCD D6 pin to digital pin 6
   LCD D7 pin to digital pin 7
   LCD BL pin to digital pin 10 (NOT USED PIN10 IS DANGEROUS FOR ARDUINO ADC IF NOT SET RIGHT)

   KEY pin to analog pin 0

   ESC Signal to digital pin 11
   ESC Ground to ground

*/


#include <Servo.h>
#include <LiquidCrystal.h>
#include <LCDKeypad.h>

//const byte LcdRsPin = 8;  //left here until I can use it.
//const byte LcdEnPin = 9;
//const byte LcdD4Pin = 4;
//const byte LcdD5Pin = 5;
//const byte LcdD6Pin = 6;
//const byte LcdD7Pin = 7;
const byte KeyPin = A0;
const byte MotorPin = 11;

int motorSpeedMin       = 10;
int motorSpeedNeutral   = 90;
int motorSpeedMax       = 180;
int motorSpeed          = motorSpeedNeutral;        //Speed of motor initiates at neutral.
int buttonScrollDelay   = 200;                      //Changes scroll rate when button is held down.

Servo motor;
LCDKeypad lcd;

void setup ()
{

  //LCD START
  lcd.begin(16, 2);                  // start LCD
  lcd.clear();
  lcd.setCursor(0, 0);


  //ESC SETUP
  //motor speed max is 180 min is 90 reverse is min 90 max 10 
  lcd.print ("ESC SETUP   ");
  delay(500);
  motor.attach(MotorPin);            //attach to pin 11 (digital)
  delay(500);                        //just a delay to let stuff get started
  motor.write(motorSpeedMin);        //writing the minimum value (arming it)
  lcd.setCursor(0, 0);
  lcd.print ("MIN         ");
  delay(1500);                       //delay to let it process that
  motor.write(motorSpeedMax);        //writes max value
  lcd.setCursor(0, 0);
  lcd.print ("MAX         ");
  delay(1500);                       //delay to let it process
  motor.write(motorSpeedNeutral);    //writes neutral
  lcd.setCursor(0, 0);
  lcd.print ("NEUTRAL     ");
  delay(1500);//delay                //again waiting

  //at this point most ESC's are armed but some may need this additional step

  motor.write(motorSpeedMin);        //back to min value
  lcd.setCursor(0, 0);
  lcd.print ("MIN         ");
  delay(500);
  motor.write(motorSpeedNeutral);    //Neutral
  lcd.setCursor(0, 0);
  lcd.print("COMPLETE     ");
  delay(1000);
}

void loop()
{
  switch (lcd.button())
  {
    case KEYPAD_LEFT:
      if (motorSpeed >= 1) {
        lcd.print("   Left -1      ");
        motorSpeed -= 1;
        delay(buttonScrollDelay);
      } else {
        lcd.print("    NOT ABLE    ");
      }
      break;
    case KEYPAD_RIGHT:
      if (motorSpeed <= 179) {
        lcd.print("    Right +1    ");
        motorSpeed += 1;
        delay(buttonScrollDelay);
      } else {
        lcd.print("    NOT ABLE    ");
      }
      break;
    case KEYPAD_DOWN:
      if (motorSpeed >= 10) {
        lcd.print("   Down -10     ");
        motorSpeed -= 10;
        delay(buttonScrollDelay);
      } else {
        lcd.print("    NOT ABLE    ");
      }
      break;
    case KEYPAD_UP:
      if (motorSpeed <= 170) {
        lcd.print("   Up +10       ");
        motorSpeed += 10;
        delay(buttonScrollDelay);
      } else {
        lcd.print("    NOT ABLE    ");
      }
      break;
    case KEYPAD_SELECT:
      lcd.print("Reset to Neutral");
      motorSpeed = 90;
      delay(buttonScrollDelay);
      break;
      delay (100);
  }
  motor.write(motorSpeed);
  lcd.setCursor(0, 0);
  lcd.print ("Speed =          ");
  lcd.setCursor(9, 0);
  lcd.print (motorSpeed);
  lcd.setCursor(0, 1);
  delay(100);
}

LCD_KEYPAD_SHIELD_ESC_SERVO_CONTROLLER.ino (3.77 KB)