Commit c7733dd9 authored by leo's avatar leo
Browse files

Initial commit

parents
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
"version": "0.2.0",
"configurations": []
}
#include "DHT.h"
#include "HX711.h"
#define DHTPIN 3
#define DHTTYPE DHT22
#define BUT_PIN 6
HX711 capteur;
int DAT = 4;
int CLK = 5;
long charge;
// Modelisation de la mesure :
// Pmes = A*Preel + B
int A = 3.38e3;
int B = 7.89e4;
// Capteur temp/humi
DHT dht(DHTPIN, DHTTYPE);
// choix de la grandeur à afficher
int dataToPrint = 0;
void setup() {
Serial1.begin(9600);
while(!Serial1); // Serial1 port serie physique
capteur.begin(DAT, CLK);
dht.begin();
pinMode(BUT_PIN, INPUT_PULLUP);
pinMode(2, OUTPUT);
attachInterrupt(digitalPinToInterrupt(BUT_PIN), select, FALLING);
}
float h;
float t;
char Serial1Msg[32];
String msg;
void loop() {
charge = capteur.read_average(10);
h = dht.readHumidity();
t = dht.readTemperature();
if (dataToPrint == 0) {
msg = ";Temp : "+String(t);
msg.toCharArray(Serial1Msg, 32);
Serial1.write(Serial1Msg);
} else if (dataToPrint == 1) {
msg = ";Hum : "+String(h);
msg.toCharArray(Serial1Msg, 32);
Serial1.write(Serial1Msg);
} else if (dataToPrint == 2) {
msg = ";Charge : "+String(getMasse(charge))+"kg";
msg.toCharArray(Serial1Msg, 32);
Serial1.write(Serial1Msg);
}
if(!digitalRead(BUT_PIN)) digitalWrite(2, 1); // test de fonctionnement
else digitalWrite(2, 0);
delay(300);
}
void select() {
dataToPrint = (dataToPrint + 1) % 3;
}
float getMasse(int pmes) {
return (float) (pmes - B)/A;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment