help making library

Can anyone help me turn this code into a library?
I tried myself but i keep getting errors even tho ut looks the same as the tutorial, every command and var gives me an err
if someone could make it and leave the files up thatd be greatly appreciated : )
im trying to make just one command called SIO(); that goes through the code snippet

Here's the working code just not in library for m lol

#include "LiquidCrystal.h"

LiquidCrystal lcd(30, 31, 32, 22, 23, 24, 25);
int incoming = 0;
int command[4] = {0, 0, 0, 0};
int place = 0;
int pin;
int state;
int pinstatus;

void setup(){
Serial.begin(9600);
lcd.begin(16, 2);

}

void loop(){
SIO();

}

void SIO(){

if(Serial.available() > 0){
incoming = (Serial.read());
if(incoming != 13){
lcd.print(char(incoming));
command[place] = incoming;
place = place++;
}
}
if(place >= 4){
place = 0;
pin = command[0] - 48;
pin = pin * 10;
pin += command[1] - 48;
if(command[2] == 'O') state = 1;
else;
if(command[2] == 'I') state = 0;
pinstatus = command[3] - 48;
pinMode(pin, state);
if(state == 1) digitalWrite(pin, pinstatus);
if(state == 0) Serial.println(digitalRead(pin));
}
}

And for clarificatio I don't need the lcd stuff in the library, that was just for me bugging
and srry for the poorly explained code, I usually don't neaten things up till it all works

I usually don't neaten things up till it all works

You'd rather debug sloppy code?

Lovely code:

    place = place++;
place++;

is equivalent to

place = place + 1;

So, your code is equivalent to

place = place = place + 1;

Seems a bit of redundancy there, no?

    command[place] = incoming;

What happens if the serial buffer contains 10 characters before the 13. The command array doesn't have unlimited room.

13? You got something against the more obvious '\n'?

    if(place >= 4){

So, it's OK if place is 14?

      pin = command[0] - 48;

pin = command[0] - '0'; would be easier to maintain. In two weeks, will you remember why you are subtracting 48 from command[0]?

Enough criticism of the code. Looking at your questions:

Can anyone help me turn this code into a library?

What part of the code? You have setup() and loop(), which are never part of a library, and one function. The function seems pretty limited in scope to be turning into a library.

But, if you are doing it to learn how, then fine. What did you try?

A library consists of a header file (.h) and a source file (.cpp).

every command and var gives me an err

So, you need to address those errors. Show us what you tried, and what errors the compiler (or linker) showed you.

13? You got something against the more obvious '\n'?

You got something about the more correct '\r'?

You got something about the more correct '\r'?

Nope. Not a thing. I usually use a compound test, to test for either '\r' or '\n', so I often forget which is 10 and which is 13.

Yeah its a bit sloppy I know, I ts the first time I tried to control it over serial so Its still pretty rough

I made the .h and. Cpp file the same way shown in the morse code example on the arduino site, and I get something about not declaring a type on my functions and every integer declaration gets an error, ill poost the actual thing after work today

im not sure if the cpp file is good since it doesn't compile past the header
and (tentativly) the reason for the 4 is that's the size of my commands so when I make the computer side of it I can send multiple commands at once, very rough but good enough for me,

And yeah I didn't think to use the char name until later lol and I musta forgot the proper use of ++

Heres my h file

 #include "Scos.H"

	int _incoming = 0;
	int _command[4] = {0, 0, 0, 0};
	int _place = 0;
	int _pin = 99;
	int _state = 0;
	int _pinstatus;


 void Scos::sio(){
      if(Serial.available() > 0){
    _incoming = (Serial.read());
    if(_incoming != 13){
    _command[_place] = _incoming;
    _place++;
    }
    }
    if(_place >= 4){
      _place = 0;
      _pin = _command[0] - 48;
      _pin = _pin * 10;
      _pin += _command[1] - 48;
      if(_command[2] == 'O') _state = 1;
      else;
      if(_command[2] == 'I') _state = 0;
      _pinstatus = _command[3] - 48;
      pinMode(_pin, _state);
      if(_state == 1) digitalWrite(_pin, _pinstatus);
      if(_state == 0) Serial.println(digitalRead(_pin));
       }
      }

And my cpp

 #ifndef Scos_h
#define Scos_h

#include "WProgram.h"
#include "HardwareSerial.h"

class Scos {
  public:
  void sio();
  private:
  int _incoming;
  int _command[4];
  int _place;
  int _pin;
  int _state;
  int _pinstatus;  
};

#endif

It will compile if its just included but when I put Scos.sio(); it says scos.cpp 12 error unqualified before '.'

It will compile if its just included but when I put Scos.sio(); it says scos.cpp 12 error unqualified before '.'

And, the compiler is right. You need to create an object of the class, before you can call methods of the class. You could make sio() a static function, and call it:

Scos::sio();

but the static method will not have access to any other members of the class. Not that that matters since you are also defining global variables of the same name in the header file.

But, what you should do is get rid of the global variables and create an instance of the class in the sketch:

Scos joe;

Then, in loop(), call the instance method:

joe.sio();

Awesome it works!
Thank you
I removed the vars from the header file and made the instance and it works perfect