|
| 1 | +/** |
| 2 | + * Example code demonstrating the LSA08_Simplified library usage. |
| 3 | + * Developed by CSD Robocon NITK |
| 4 | + * |
| 5 | + * This is free software. You can redistribute it and/or modify it under |
| 6 | + * the terms of MIT Licence. |
| 7 | + * To view a copy of this license, visit http://opensource.org/licenses/mit-license.php |
| 8 | + * |
| 9 | + * version: 1.0.0 |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * In this example, the LSA08 line sensor is interfaced with an Arduino UNO via SoftwareSerial |
| 14 | + * and the reading from the sensor is displayed on the serial monitor. |
| 15 | + * |
| 16 | + * Connections: |
| 17 | + * LSA08 | Arduino UNO Pin |
| 18 | + * --------------+--------------------------------------- |
| 19 | + * Port A - 1 | 2 |
| 20 | + * Port A - 2 | 3 |
| 21 | + * Port A - 3 | 4 |
| 22 | + * Port A - 9 | - (External Power Supply 7.5V - 20V) |
| 23 | + * Port A - 10 | GND (External Power Supply GND) |
| 24 | + */ |
| 25 | + |
| 26 | +#include "LSA08_Simplified.h" |
| 27 | +#include <SoftwareSerial.h> |
| 28 | + |
| 29 | +// Create a software serial object with pins 2 and 3 |
| 30 | +SoftwareSerial mySerial(2, 3); |
| 31 | + |
| 32 | +// Create a LSA08 sensor object |
| 33 | +LSA08 sensor = LSA08(&mySerial, 9600, 1, 4); |
| 34 | + |
| 35 | +void setup() { |
| 36 | + Serial.begin(9600); |
| 37 | + |
| 38 | + // Disable the line position data coming from the LSA08 |
| 39 | + sensor.disable_stream(); |
| 40 | + |
| 41 | + // Set LSA08 UART mode to analog data |
| 42 | + sensor.set_uart_mode(UART_MODE_ANALOG); |
| 43 | + |
| 44 | + // Set line mode to read dark lines |
| 45 | + sensor.set_line_mode(DARK_LINE); |
| 46 | + |
| 47 | + // Trigger an auto-calibration. Calibration takes sometime in the sensor, hence the 5 second delay |
| 48 | + sensor.calibrate(); |
| 49 | + delay(5000); |
| 50 | + |
| 51 | + // Enable the line position data from the LSA08 |
| 52 | + sensor.enable_stream(); |
| 53 | +} |
| 54 | + |
| 55 | +void loop() { |
| 56 | + // Get the line position data and print it |
| 57 | + int pos = sensor.read_line(); |
| 58 | + Serial.println(pos); |
| 59 | +} |
0 commit comments