Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
added ProximitySwitch class
  • Loading branch information
nihal-sahu committed Mar 23, 2022
commit 01f1e74842c7a5569137cf7a5fd321499c3efa7d
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{};
[[nodiscard]] bool reset() override;
[[nodiscard]] bool update() override;

private:
AnalogIn m_proximity_in_adc;
};
} // namespace Sensor
14 changes: 14 additions & 0 deletions libs/sensors/src/ProximitySwitch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#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()
{
float proximity_reading = m_proximity_in_adc.read();

return proximity_reading;
}