torsdag 26 april 2012

Hey there folks!

My name is Aid Vllasaliu and I like programming.

This blog is dedicated to my very first Arduino library that I call XELFA, which stands for Xaid Essential Library For Arduino. Sorry for the long potato, but I had to find a good short name available here on blogspot.

So, what does XELFA do?
XELFA contains a couple of functions and procedures that in my opinion are essential for quicker programming.

The two different parts that makes XELFA is
1. the string handler/manipulator, also called Stringball
2. the board command handler.

One thing that I found important straight away as soon as I started to program my Arduino board was serial communication to/from my computer, Mac to be specific.

The serial communication itself is not tricky at all, but I wanted to have better control over the data that was sent to the Arduino so that I could save memory and rapidly try things without having to
upload sketches with barely one line of code change.

Let me give you an example of the string handler:
I'm modifying the dashboard of my car, and I wanted to control the RPM meter from the computer
to quickly map some values.

(Click here to go to Project X80)

Normally I'd have to change the Arduino code and the burn the sketch, every single time I changed a value.
A quicker way to map values would be to make an application that sends serial data from the computer to the Arduino.

(Click here to go to my other project Delphuino where I talk about Delphi programming and Arduino programming in harmony)

However, a normal program would send commands in a step-by-step fashion, something like the following:
1. Send "SET", so that the Arduino knows that you want to Set a certain value.
2. Send "RPM". Now Arduino knows that you want to Set the RPM value.
3. Send "4500". Arduino now knows that you want to Set the RPM value to 4500.

I wont do that, thats too slow. So what I did was to port a Delphi unit that I made and use a lot which
handles commands.
Commands are like procedures, they contain a command name and command parameters.

So that step-by-step thingy above would be alot easier and quicker to use if it would be sort of a command.
What would that command look like? It would look like this: "RPM,4500".

Stringball functions are
  • int FindStr(String Str, String SubStr)
    Search for a substring inside another string.
    Returns the position of the first character of the substring.
  • int FindStrPass(String Str, String SubStr, int Passes);
    Same as above, only that if you are looking for the substring, lets say "XYZ" and your main
    string contains 5 of those substrings, you can bypass for example 4 of them and get the position of the fifth.
  • int CountStr(String Str, String SubStr);
    This will count how many times a substring is present in a main string.
  • String ReplaceStr(String Str, String Replace, String ReplaceWith);
    This will replace a specified substring in a main string.
  • String GetListItem(String List, int Index, String Spacer);
    This will extract an item/parameter from a list/command
  • int CountListItems(String List, String Spacer);
    This will count all the items/parameters.
  • String InsertListItem(String List, int Index, String StrToInsert, String Spacer);
    This will insert a specified item/parameter.
  • String DeleteListItem(String List, int Index, String Spacer);
    This will delete a specified item/parameter.
  • String ReplaceListItem(String List, int Index, String NewStr, String Spacer);
    This will replace an existing item/parameter with a new specified one.
  • int StrToInt(String Str)
    This will convert a string to an integer.
Note: the parameter "Spacer" defines what separates parameters from each other.


And for the Board Command Handler, all I need to say is that you can send commands such as "Pin,13,128" which basically sets the PWM value of pin 13, or the SMD LED, to 128.

Summary:
1. XELFA contains a string handler/manipulator.
2. XELFA contains a Board Command Handler which is controlled by external devices.


I have done my best to keep this library as simple as possible, because I know how important it is to be able to quickly get my code working without having to look for stuff on the interwebs.

Download XELFA >>here<<
It contains the library (duuh!), a couple of examples.

Have fun :)


By the way, dont forget to visit my other two blogs :)

kthxbye