mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
not working version
This commit is contained in:
34
include/items/SensorUltrasonicClass.h
Normal file
34
include/items/SensorUltrasonicClass.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorUltrasonic : public SensorConvertingClass {
|
||||
public:
|
||||
SensorUltrasonic() : SensorConvertingClass(){};
|
||||
|
||||
int SensorUltrasonicRead(String key, String pin) {
|
||||
int trig = selectFromMarkerToMarker(pin, ",", 0).toInt();
|
||||
int echo = selectFromMarkerToMarker(pin, ",", 1).toInt();
|
||||
int value;
|
||||
|
||||
digitalWrite(trig, LOW);
|
||||
delayMicroseconds(2);
|
||||
digitalWrite(trig, HIGH);
|
||||
delayMicroseconds(10);
|
||||
digitalWrite(trig, LOW);
|
||||
long duration_ = pulseIn(echo, HIGH, 30000); // 3000 µs = 50cm // 30000 µs = 5 m
|
||||
value = duration_ / 29 / 2;
|
||||
|
||||
value = this->mapping(key, value);
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen(key, "");
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
MqttClient::publishStatus(key, String(valueFl));
|
||||
Serial.println("[I] sensor '" + key + "' data: " + String(valueFl));
|
||||
return value;
|
||||
}
|
||||
};
|
||||
extern SensorUltrasonic* mySensorUltrasonic;
|
||||
Reference in New Issue
Block a user