Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions libs/sensors/include/ProximitySwitch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "Sensor.h"
#include "mbed.h"

namespace Sensor {
class ProximitySwitch final : Sensor {
public:
ProximitySwitch(PinName proximity_in);

// read returns 1 for HIGH, and 0 for LOW
float read() override{};
float alternateRead() override{};
bool getStatus() const override{};
Comment thread
nihal-sahu marked this conversation as resolved.
Outdated
[[nodiscard]] bool reset() override;
[[nodiscard]] bool update() override;
Comment thread
nihal-sahu marked this conversation as resolved.
Outdated

private:
AnalogIn m_proximity_in_adc;
};
} // namespace Sensor
12 changes: 12 additions & 0 deletions libs/sensors/src/ProximitySwitch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "ProximitySwitch.h"

using namespace Sensor;

ProximitySwitch::ProximitySwitch(PinName proximity_in) : m_proximity_in_adc(proximity_in) {}

/*https://www.dfrobot.com/product-2025.html*/
float ProximitySwitch::read() {
Comment thread
nihal-sahu marked this conversation as resolved.
float proximity_reading = m_proximity_in_adc.read();
Comment thread
nihal-sahu marked this conversation as resolved.
Outdated

return proximity_reading;
}