How to make commands?

How can I create commands and put them in my code?

I want to use the commands in the serial monitor.

What do you mean?

Search for : arduino command interpreter I often write my own, in most cases I use a single character: 'H' and '?' for help info, 'L' for led, and so on.

kashashin: How can I create commands and put them in my code?

I want to use the commands in the serial monitor.

In this message I have posted an example sketch:

http://forum.arduino.cc/index.php?topic=301466.msg2101661#msg2101661

The sketch understands different devices like "led", "motor", "pump", "relay". And for each device three commands are supported: "on", "off", "click"

So from the serial monitor you can send commands like: motor on pump off led click 500

where the "click" action perhaps needs some explanation: The "click" command is executing a non-blocking action sequence of - "switch on" - "stay on for the number of milliseconds given as a parameter" - "switch off"

I use this when doing simple EEPROM updates to my calibrations.

void eeprom1()
{
  while (Serial.available() > 0)     
{
    char inByte = Serial.read();

  
    while(inByte == 'r')
    {
      eepromr();        //this function reads the address and displays the value at said address
      break;
    }
    while(inByte == 'w')
    {
      eepromwr();    //this function writes to the address and displays the written value
      break;
    }
  }

}

It works quit well.

Bill

A very simple example of sending a command from the serial monitor to the arduino.

// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

int ledPin = 13;
String readString;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT); 
  Serial.println("serial on/off test 0021"); // so I can keep track
}

void loop() {

  while (Serial.available()) {
    delay(3);  
    char c = Serial.read();
    readString += c; 
  }

  if (readString.length() >0) {
    Serial.println(readString);

    if (readString == "on")     
    {
      digitalWrite(ledPin, HIGH);
      Serial.println("LED ON");
    }
    if (readString == "off")
    {
      digitalWrite(ledPin, LOW);
      Serial.println("LED OFF");
    }
    readString="";
  } 
}