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:
SebasKoedam
2024-05-21 12:55:14 +02:00
parent a4907f00c8
commit 39f3d4bb1d
9 changed files with 82 additions and 35 deletions

View File

@@ -0,0 +1,12 @@
#include "PositionSensor.h"
PositionSensor sensor(15); // Sensor Pin
void setup() {
sensor.begin();
}
void loop() {
sensor.Measure();
delay(1000);
}

View 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);
}

View 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

View 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
}