This library is for the Cytron Line Sensing Array: LSA08 (reference here).
It is suggested that you download the entire repository and then select this folder, so that you can enjoy the benifits of VCS like git. It makes it simpler to update the contents whenever patch fixes are done. You can simply open a terminal (or gitbash on windows), go to the folder where you want to save this repository and type the following command.
git clone https://github.com/shashank3199/LSA08.git
Not recommended: You can download only this folder by clicking here
Move this folder into the arduino libraries folder on your PC. If you don't know where the libraries folder of your arduino is, you can click here.
Also, this Library makes use of the DebuggerSerial Library. For More Information on this, click here.
In order to use this library, you must do the following:
- Include the header file
LSA08.h
(the LSA08 library folder must be in your arduino libraries folder). - Create an object of class
LSA08
. You can pass the constructor parameters to initialize here itself, or leave it as a simple object declaration. - Initialize the Serial on which the LSA is attached using the
AttachSerial
function. You may optionally initialize and attach a debugger serial as well (usingdebugger.Initialize
function on the object). You can access the debugger using thedebugger
variable of the class.
The Library uses the LSA Module with the following Pin Out -
Menu | Description |
---|---|
LCD Contrast (LCD CON) | Setting the contrast of LCD. |
Calibration (CALB) | Calibrate LSA08 to the colour brightness of the line and background. |
Line Mode (LINEMODE) | Setting LSA08 to be Dark On (for dark line and bright background) or Light On (for bright line and dark background). |
Threshold (THRES) | Set according to the surface condition of the line. It is the number of Lines in a bar as shown on the LCD. The threshold value can be set from 0 to 7. |
Junction Width (J WIDTH) | The number of bar chart on LCD for a junction crossing. |
UART addressing (UART ADD) | Application Not Applicable here. |
UART Baudrate (BAUDRATE) | Setting the baudrate of the UART Communication. |
UART Mode (UARTMODE) | To be Set as 2 |
LCD Backlight (LCD B/L) | Setting the LCD backlight brightness |
Exit (EXIT) | Exit Menu |
Note: Press and hold Mode button on any main menu will exit the menu.
Baudrate No. | Baudrate |
---|---|
0 | 9600 |
1 | 19200 |
2 | 38400 |
3 | 57600 |
4 | 115200 |
5 | 230400 |
This example show you to Read values from the LSA using the LSA08
library on Serial2 without the use of any Buffer.
File: ./examples/SerialRead/SerialRead.ino
We simply follow the following steps:
- Include library
- Create object
- Initialize Serials. LSA08 on Serial2 and debugger on Serial. Keep in mind to match the baud rates.
- Initialize debugger. Name it
LSA
. - Then start a loop
- Read LSA Values using ReadLSA Function.
- The Values will be printed by the Debugger Object.
- Re-run the loop
This example show you to Read values from the LSA using the LSA08
library on Serial2 using a Buffer or by using the Enable Pin (if not Grounded Electronically).
File: ./examples/SerialRead_Buffer/SerialRead_Buffer.ino
We simply follow the following steps:
- Include library
- Create object
- Initialize Serials. LSA08 on Serial2 and debugger on Serial. Keep in mind to match the baud rates. Also, set the Pin Value for the Buffer Control Pin (or Enable Pin) and Active State of the Buffer Control (LOW incase of the Default Enable Pin).
- Initialize debugger. Name it
LSA
. - Then start a loop
- Read LSA Values using ReadLSA Function.
- The Values will be printed by the Debugger Object.
- Re-run the loop
This example show you to Read values from the LSA using the LSA08
library using the Analog Pin.
File: ./examples/AnalogRead/AnalogRead.ino
We simply follow the following steps:
- Include library
- Create object
- Initialize Serials. LSA08 on Pin No: 8 and debugger on Serial.
- Initialize debugger. Name it
LSA
. - Then start a loop
- Read LSA Values using ReadLSA Function.
- The Values will be printed by the Debugger Object.
- Re-run the loop
The files in the library are :
This is the Header file and contains the Class Blueprint (Prototype).
This file contains the Definiton for the Class Member Functions Prototyped in the Header File.
The Description file containing details about the library. The file that you looking at right now.
Let's explore the contents of the class, but first, we also have literals defined for general purpose use (using #define
). They are:
Name | Value | Purpose |
---|---|---|
MODE_SERIAL | 0 | Value passed to select the Serial Mode for receiving Values. |
MODE_ANALOG | 1 | Value passed to select the Analog Mode for receiving Values. |
Name | Value | Purpose |
---|---|---|
BUFFER_OFF | 0 | Indicates that the Serial is not connected to any Buffer. |
BUFFER_ON | 1 | Indicates that the Serial is connected to a Buffer. |
Let's explore the class now
- HardwareSerial *LSASerial: This is the serial on which the LSA operates.
- int currentValue: The LSA Value at Present.
- int previousValue: The Last Non - 255 Value of the LSA.
- int analogPin: Pin Number to which the Analog Pin of the LSA is connected.
- int flagValue: Reference Value of the LSA indicating the following -
Flag Value | LSA Value ( Range ) |
---|---|
0 | 0 |
1 | 1 - 34 |
2 | 35 |
3 | 36 - 69 |
4 | 70 |
5 | 255 |
- bool bufferStatus: Indicator whether the LSA is connected to a buffer or not.
- int bufferPin: Pin Number of the Buffer Control Pin.
- bool bufferPinStatus: Active Status for the Buffer Control Pin.
- voidClearLSA ( ) : Clear the Junk Values from the LSA.
- voidSetFlag ( ) : Set the Flag Value for the LSA.
- DebuggerSerial debugger: The debugger for the class. Check the DebuggerSerial documentation for more on this.
- LSA08 ( ) : Empty constructor for the class.
- LSA08 ( HardwareSerial *LSASerial ) : To attach a pre-initialized serial to the LSA. This function calls the AttachSerial member function along with the previously mentioned Constructor using Constructor Delegation.
- LSA08 ( HardwareSerial *LSASerial , int bufferPin , bool bufferPinStatus ) : To attach a pre-initialized serial to the LSA on a Buffer. This function calls the SetBuffer member function along with the previously mentioned Constructor using Constructor Delegation.
- LSA08 ( int analogPin ) : To Set the Pin Number to which the Analog Pin of the LSA is connected. This function calls the AttachAnalogPin member function.
-
bool operator == ( int flagValue ) : Checks for Equality of a Flag Value directly with the LSA Variable.
-
bool operator != ( int flagValue ) : Checks for Inequality of a Flag Value directly with the LSA Variable.
-
operator int ( ) : Implicit Type Conversion from Object Type: LSA08 to int Type for Easy Assignment and Comparision.
-
void SetBuffer ( int bufferPin , int bufferPinStatus ) : Sets the Buffer Control Pin and Value for the LSA.
-
void AttachSerial ( HardwareSerial *LSASerial ) : Attach the Serial to the LSA.
-
void AttachSerial ( HardwareSerial *LSASerial , int bufferPin , bool bufferPinStatus ) : Attach the Serial to the LSA. and Sets the Buffer Control Pin and Value.
-
void AttachAnalogPin ( int analogPin ) : Set the Analog Pin for Receiving Value in Analog Mode.
-
int ReadLSA ( ) : To Receive and Return the Current LSA Value.
-
int GetPreviousValue ( ) : To Return the Last Non - 255 Value of the LSA.