mirror of
https://github.com/MOSH-Insa-Toulouse/5ISS-2024-2025-MARIN--MULLER-BOUJON.git
synced 2025-06-08 14:00:49 +02:00
some changes
This commit is contained in:
commit
87f1e992b9
3 changed files with 51 additions and 0 deletions
27
lib/sensor/sensor.cpp
Normal file
27
lib/sensor/sensor.cpp
Normal 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
17
lib/sensor/sensor.hpp
Normal 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
|
|
@ -4,6 +4,8 @@
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
|
|
||||||
|
#include "sensor.hpp"
|
||||||
|
|
||||||
#define SCREEN_WIDTH 128
|
#define SCREEN_WIDTH 128
|
||||||
#define SCREEN_HEIGHT 64
|
#define SCREEN_HEIGHT 64
|
||||||
|
|
||||||
|
@ -13,6 +15,8 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
|
||||||
// RN2483Serial using RX2 and TX2
|
// RN2483Serial using RX2 and TX2
|
||||||
HardwareSerial RN2483Serial(2);
|
HardwareSerial RN2483Serial(2);
|
||||||
|
|
||||||
|
Sensor gaz_sensor;
|
||||||
|
|
||||||
void printSSD1306(String text) {
|
void printSSD1306(String text) {
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
|
@ -92,6 +96,7 @@ void setup() {
|
||||||
|
|
||||||
// Initialize RN2483A Serial communication
|
// Initialize RN2483A Serial communication
|
||||||
RN2483Serial.begin(57600);
|
RN2483Serial.begin(57600);
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
// Initialize SSD1306
|
// Initialize SSD1306
|
||||||
Init_SSD1306();
|
Init_SSD1306();
|
||||||
|
@ -99,6 +104,8 @@ void setup() {
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
test_RN2483A();
|
test_RN2483A();
|
||||||
|
Serial.print("Value from sensor: ");
|
||||||
|
Serial.println(gaz_sensor.get_value());
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
// Test communication to gateway
|
// Test communication to gateway
|
||||||
|
|
Loading…
Add table
Reference in a new issue