feat: Add Arduino code for position tracking
The code changes include adding a new Arduino sketch for position tracking. The sketch is located at `code/arduino/Position-tracking/Position-tracking.ino`. Additionally, a new class `PositionSensor` is added with its corresponding header and implementation files. This class handles the position sensor functionality and includes methods for initialization and measurement. The commit message suggests that the changes are a new feature addition related to position tracking in the Arduino code.
This commit is contained in:
3
.vscode/arduino.json
vendored
3
.vscode/arduino.json
vendored
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"port": "COM3",
|
"port": "COM3",
|
||||||
"board": "esp32:esp32:esp32s3"
|
"board": "esp32:esp32:esp32s3",
|
||||||
|
"sketch": "code\\arduino\\Position-tracking\\Position-tracking.ino"
|
||||||
}
|
}
|
1
.vscode/c_cpp_properties.json
vendored
1
.vscode/c_cpp_properties.json
vendored
@@ -225,7 +225,6 @@
|
|||||||
"C:\\Users\\sebas\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\2.0.16\\tools\\sdk\\esp32s3\\qio_qspi\\include",
|
"C:\\Users\\sebas\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\2.0.16\\tools\\sdk\\esp32s3\\qio_qspi\\include",
|
||||||
"C:\\Users\\sebas\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\2.0.16\\cores\\esp32",
|
"C:\\Users\\sebas\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\2.0.16\\cores\\esp32",
|
||||||
"C:\\Users\\sebas\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\2.0.16\\variants\\esp32s3",
|
"C:\\Users\\sebas\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\2.0.16\\variants\\esp32s3",
|
||||||
"C:\\Users\\sebas\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\2.0.16\\libraries\\BLE\\src",
|
|
||||||
"c:\\users\\sebas\\appdata\\local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32s3-elf-gcc\\esp-2021r2-patch5-8.4.0\\xtensa-esp32s3-elf\\include\\c++\\8.4.0",
|
"c:\\users\\sebas\\appdata\\local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32s3-elf-gcc\\esp-2021r2-patch5-8.4.0\\xtensa-esp32s3-elf\\include\\c++\\8.4.0",
|
||||||
"c:\\users\\sebas\\appdata\\local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32s3-elf-gcc\\esp-2021r2-patch5-8.4.0\\xtensa-esp32s3-elf\\include\\c++\\8.4.0\\xtensa-esp32s3-elf",
|
"c:\\users\\sebas\\appdata\\local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32s3-elf-gcc\\esp-2021r2-patch5-8.4.0\\xtensa-esp32s3-elf\\include\\c++\\8.4.0\\xtensa-esp32s3-elf",
|
||||||
"c:\\users\\sebas\\appdata\\local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32s3-elf-gcc\\esp-2021r2-patch5-8.4.0\\xtensa-esp32s3-elf\\include\\c++\\8.4.0\\backward",
|
"c:\\users\\sebas\\appdata\\local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32s3-elf-gcc\\esp-2021r2-patch5-8.4.0\\xtensa-esp32s3-elf\\include\\c++\\8.4.0\\backward",
|
||||||
|
12
code/arduino/Position-tracking/Position-tracking.ino
Normal file
12
code/arduino/Position-tracking/Position-tracking.ino
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "PositionSensor.h"
|
||||||
|
|
||||||
|
PositionSensor sensor(15); // Sensor Pin
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
sensor.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
sensor.Measure();
|
||||||
|
delay(1000);
|
||||||
|
}
|
13
code/arduino/Position-tracking/PositionSensor.cpp
Normal file
13
code/arduino/Position-tracking/PositionSensor.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include "PositionSensor.h"
|
||||||
|
|
||||||
|
PositionSensor::PositionSensor(int pin) : _pin(pin) {}
|
||||||
|
|
||||||
|
void PositionSensor::begin() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
pinMode(_pin, INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PositionSensor::Measure() {
|
||||||
|
int value = analogRead(_pin);
|
||||||
|
Serial.println(value);
|
||||||
|
}
|
15
code/arduino/Position-tracking/PositionSensor.h
Normal file
15
code/arduino/Position-tracking/PositionSensor.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef PositionSensor_h
|
||||||
|
#define PositionSensor_h
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
class PositionSensor {
|
||||||
|
public:
|
||||||
|
PositionSensor(int pin);
|
||||||
|
void begin();
|
||||||
|
void Measure();
|
||||||
|
private:
|
||||||
|
int _pin;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
0
code/arduino/Position-tracking/SendData.cpp
Normal file
0
code/arduino/Position-tracking/SendData.cpp
Normal file
0
code/arduino/Position-tracking/SendData.h
Normal file
0
code/arduino/Position-tracking/SendData.h
Normal file
40
code/arduino/Position-tracking/test/test.ino
Normal file
40
code/arduino/Position-tracking/test/test.ino
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#include <BLEDevice.h>
|
||||||
|
#include <BLEUtils.h>
|
||||||
|
#include <BLEServer.h>
|
||||||
|
|
||||||
|
// Define the BLE service and characteristic UUIDs
|
||||||
|
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
|
||||||
|
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize the BLE environment
|
||||||
|
BLEDevice::init("ESP32-S3");
|
||||||
|
|
||||||
|
// Create a BLE server
|
||||||
|
BLEServer *pServer = BLEDevice::createServer();
|
||||||
|
|
||||||
|
// Create a BLE service
|
||||||
|
BLEService *pService = pServer->createService(SERVICE_UUID);
|
||||||
|
|
||||||
|
// Create a BLE characteristic
|
||||||
|
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
|
||||||
|
CHARACTERISTIC_UUID,
|
||||||
|
BLECharacteristic::PROPERTY_READ |
|
||||||
|
BLECharacteristic::PROPERTY_WRITE
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set the initial value of the characteristic
|
||||||
|
pCharacteristic->setValue("Hello, World!");
|
||||||
|
|
||||||
|
// Start the service
|
||||||
|
pService->start();
|
||||||
|
|
||||||
|
// Start advertising the BLE service
|
||||||
|
BLEAdvertising *pAdvertising = pServer->getAdvertising();
|
||||||
|
pAdvertising->addServiceUUID(SERVICE_UUID);
|
||||||
|
pAdvertising->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Nothing to do here for this example
|
||||||
|
}
|
@@ -1,33 +0,0 @@
|
|||||||
#include <BLEDevice.h>
|
|
||||||
#include <BLEServer.h>
|
|
||||||
|
|
||||||
// Define the service UUID
|
|
||||||
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
|
|
||||||
|
|
||||||
// Define the characteristic UUID
|
|
||||||
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
// Create a BLE server
|
|
||||||
BLEServer *pServer = BLEDevice::createServer();
|
|
||||||
|
|
||||||
// Create a BLE service
|
|
||||||
BLEService *pService = pServer->createService(SERVICE_UUID);
|
|
||||||
|
|
||||||
// Create a BLE characteristic
|
|
||||||
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
|
|
||||||
CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ);
|
|
||||||
|
|
||||||
// Set the characteristic value
|
|
||||||
pCharacteristic->setValue("Hello, Bluetooth!");
|
|
||||||
|
|
||||||
// Start the service
|
|
||||||
pService->start();
|
|
||||||
|
|
||||||
// Start advertising the service
|
|
||||||
pServer->getAdvertising()->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
// Nothing to do here
|
|
||||||
}
|
|
Reference in New Issue
Block a user