some changes

This commit is contained in:
Lemonochrme 2024-12-03 16:01:10 +01:00
commit 87f1e992b9
3 changed files with 51 additions and 0 deletions

27
lib/sensor/sensor.cpp Normal file
View file

@ -0,0 +1,27 @@
#include "sensor.hpp"
#include <Arduino.h>
Sensor::Sensor()
{}
void Sensor::init(const uint8_t pin)
{
_pin = pin;
pinMode(_pin, INPUT);
digitalWrite(_pin, HIGH);
}
float Sensor::get_value()
{
/*
float sensor_volt;
float RS_gas; // Get value of RS in a GAS
float ratio; // Get ratio RS_GAS/RS_air
int sensorValue = analogRead(A0);
sensor_volt=(float)sensorValue/1024*5.0;
RS_gas = (5.0-sensor_volt)/sensor_volt; // omit *RL
//-Replace the name "R0" with the value of R0 in the demo of First Test
ratio = RS_gas/R0; // ratio = RS/R0
*/
return ((analogRead(_pin))/1024*5.0);
}

17
lib/sensor/sensor.hpp Normal file
View file

@ -0,0 +1,17 @@
#ifndef HEADER_SENSOR
#define HEADER_SENSOR
#include <Arduino.h>
constexpr uint8_t SENSOR_PIN = 36;
class Sensor {
public:
Sensor();
void init(const uint8_t pin);
float get_value();
private:
uint8_t _pin;
};
#endif // HEADER_SENSOR

View file

@ -4,6 +4,8 @@
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "sensor.hpp"
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
@ -13,6 +15,8 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// RN2483Serial using RX2 and TX2
HardwareSerial RN2483Serial(2);
Sensor gaz_sensor;
void printSSD1306(String text) {
display.clearDisplay();
display.setCursor(0, 0);
@ -92,6 +96,7 @@ void setup() {
// Initialize RN2483A Serial communication
RN2483Serial.begin(57600);
Serial.begin(115200);
// Initialize SSD1306
Init_SSD1306();
@ -99,6 +104,8 @@ void setup() {
void loop() {
test_RN2483A();
Serial.print("Value from sensor: ");
Serial.println(gaz_sensor.get_value());
delay(1000);
// Test communication to gateway