I have written quite a few programs and used quite a few programs from different sources, the main difference between my programs and the ones I copy from places like the arduino examples is that most of them use libraries.
Does anyone know of somewhere that teaches the use of libraries?
I have tried to understand the ones that include the keyword files such as
but don't quite understand them.
Some of the libraries don't even come with keyword files such as the matrix one.
What I need is a list of the commands of a library and hopefully some examples of what each command does.
Keyword files are simple text files that contain details that pertain to that specific library. For example, the LiquidCrystal library has a keywords.txt file. In that file, you will find entries like:
setCursor KEYWORD2
Therefore, when you create a LiquidCrystal object, such as lcd, and use it in the Arduino IDE, the IDE can look at your code and when it sees:
lcd.setCursor(0,0);
it knows that setCursor is a keyword for the library and it sets it to the color scheme dictated by the KEYWORD2 attribute. KEYWORD1 is usually reserved for classes defined in the library and LITERAL1 is used for #defines that are specific to the library. A keyword text file is not required for a library, but most provide one as a convenience.
thanks for the replies.
I am looking for some information about how to use the libraries.
As the LiquidChrystal library has been mentioned I took a look at that, loaded the example and purchased a liquid chrystal. The one I have has only one line of 16 characters but it still works.
I have had a play with it to try to get as much information out of the library as I can. Changing the program to get different instructions from the library as I understand them.
econjack you say the setCursor instruction sets the color scheme? are you sure? I think I am using it to set column,row.
I could find nowhere that tells me it needs two variables to make it work but copied the line in the example.
I see liquidCrystal.lcd (12, 11, 5, 4, 3, 2) at the start of the sketch, I assume this is setting the variable 'lcd' so the program knows when you use it, ie lcd.setCursor(6,1) and I assume the numbers set the pins of the arduino to tasks such as 'rs' and 'enable' but the program has a long list of these numbers i.e.
LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
there are 6 numbers in the line from the example program but ,I am assuming, 8 numbers in the instruction above. This is only one of a long list of similar lines in the library programme and some have only 6 numbers, does the program use one of the list to set up the pins and if so how does it know which? There is nowhere that tells me I need to set this up in the library files so to go back to my original question is there somewhere I can get this info?
I am just concentrating on the liquidCrystal at the moment but this is true of every library.
There are questions I don't even know to ask because I don't know the facility exists, for instance I have seen 'change between 4 and 8 bit'
if (fourbitmode)
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
else
_displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
but have no idea how to do it.
econjack you say the setCursor instruction sets the color scheme? are you sure? I think I am using it to set column,row.
I could find nowhere that tells me it needs two variables to make it work but copied the line in the example.
No, that's not what I said. I said:
setCursor is a keyword for the library and it sets it to the color scheme dictated by the KEYWORD2 attribute.
So, if your Serial.println() method call is displayed with an orange color, then lcd.setCursor() would be set with that same color. If you are unhappy with one of those colors, you can change it via the theme.txt file, which is usually found off the main IDE directory (e.g., C:/ArduinoIDE/lib/theme/theme.txt). The main keyword.txt file is in the same lib directory (e.g., C:/ArduinoIDE/lib/keyword.txt). The purpose of the keyword.txt file located within a given library's directory is to flag any keywords or constants that the library reserves for its own use.
ok econjack thank you
when you said ' IT sets IT to the colour' I thought you meant setCursor set the colour.
PaulS
One of the examples I have been having trouble with recently has been the matrix one. I just want to put a letter (or symbol such as an arrow) in the middle of an 8x8 matrix but the example uses the library and I can't understand how to use libraries, so I can't stop it scrolling, I intend using it as a signal on a garden railway, displaying different symbols depending on the situation but wanting to be able to do it for myself (not just asking for a program written for me), hence the request for more info about how to use libraries.
One of the examples I have been having trouble with recently has been the matrix one. I just want to put a letter (or symbol such as an arrow) in the middle of an 8x8 matrix but the example uses the library and I can't understand how to use libraries, so I can't stop it scrolling,
Your fundamental assumption here, that we know what "the library" means, is fatally flawed.
my fundamental assumption is that when you ask me what libraries in the examples I am having trouble with and I reply
One of the examples I have been having trouble with recently has been the matrix one.
I assume you can work out for your self that the library I am referring to is the matrix library in the arduino software i.e. maxmatrix but maybe I am wrong.
I assume you can work out for your self that the library I am referring to is the matrix library in the arduino software i.e. maxmatrix but maybe I am wrong.
Yes, you are wrong. I have never heard of the maxmatrix library and it is not installed on my system so how would I know ?
If I said that I was having problems with the servo library but failed to mention which of the many servo libraries that I was using then how would you know ?
I don't know what version of ide you are using but maxmatrix is in my examples.
My original question is still valid.
I am not wanting someone to take me through every library with a list of the instructions, I was just hoping someone would explain to me, if an explanation is possible, how we find out how a library works and what the instructions are that make it work.
The more I try to work it out for myself the more I think it is a case of lots of coffee while I read and try to understand the programming in the .h and .ccp files. I was just hoping for some pointers in the forum but all I get is critics just finding fault.
I don't know what version of ide you are using but maxmatrix is in my examples.
and equally I don't know which version you are using. The fact that you have the maxmatrix library and that it appears in the examples proves nothing as for all I know you installed it, which I suspect is the case.
A well supported library will include an example or examples of its use, preferably well annotated with meaningful comments. Failing that your next port of call should the the .h file where you can see the library functions and their parameters if any. For more detail you need to look at the .cpp file. It is also useful to search this forum where you will often find people with problems with libraries from which you can find sample code and explanations/solutions to the problems.
thank you jimbo that is EXACTLY what I wanted.
I was unaware until I read the page you have linked to (how do you make a link and just shows this like that?)
that all I am doing is calling functions from a .cpp sketch to use in my own sketches. I was hoping to get to understand libraries before I wrote my own but the page you linked to explains it very well.
I hope that also explains why I was looking for keyword lists Nick. I know how to find them now.
Thanks jimbo.