#include <LiquidCrystal_I2C.h>
#include <Streaming.h>
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include "SHT31.h"
#define Pot A3
#define Bouton 2
#define MIN_POT 0
#define MAX_POT 1023
#define MIN_TEMP 19
#define MAX_TEMP 35
#define MIN_PLATEAU 1
#define MAX_PLATEAU 9
#define BROCHE_BOUTON 2
#define BROCHE_NEO 4
#define BROCHE_SHT31 7
LiquidCrystal_I2C LCD(0x27, 16, 2);
Adafruit_NeoPixel strip(16, BROCHE_NEO, NEO_GRB + NEO_KHZ800);
SHT31 sht31;
void setup() {
Serial.begin(9600);
LCD.begin(16, 2);
strip.show();
strip.begin();
sht31.begin(7);
LCD.backlight();
LCD.setCursor(0, 0);
LCD << "R:";
LCD.setCursor(6, 0);
LCD << "P:";
LCD.setCursor(10, 0);
LCD << "* T:";
LCD.setCursor(0, 1);
LCD << "BL :";
LCD.setCursor(10, 1);
LCD << "RG :";
}
void loop() {
int valeurPot = analogRead(Pot);
int etatBouton = digitalRead(Bouton);
static int compteurBouton;
int valeurPlateau2;
int valeurTemp2;
if (etatBouton == HIGH)
{
compteurBouton++;
}
float temperature = sht31.getTemperature();
LCD.setCursor(14, 0);
LCD.print(temperature);
if (compteurBouton%2==0)
{
if (digitalRead(BROCHE_BOUTON))
{
while(digitalRead(BROCHE_BOUTON));
delay(50);
}
int valeurPlateau = map(valeurPot,
MIN_POT,
MAX_POT,
MIN_PLATEAU,
MAX_PLATEAU);
LCD.setCursor(5,0);
LCD.print(" ");
LCD.setCursor(8,0);
LCD.print(valeurPlateau);
LCD.print("*");
valeurPlateau2=valeurPlateau;
}
else
{
if (digitalRead(BROCHE_BOUTON))
{
while(digitalRead(BROCHE_BOUTON));
delay(50);
}
int valeurTemp = map(valeurPot,
MIN_POT,
MAX_POT,
MIN_TEMP,
MAX_TEMP);
if (valeurPlateau2>=10)
{
LCD.setCursor(10,0);
LCD.print(" ");
}
else
{
LCD.setCursor(9,0);
LCD.print(" ");
}
LCD.setCursor(3, 0);
LCD.print(valeurTemp);
LCD.print("*");
valeurTemp2=valeurTemp;
}
int vraiPlateau = valeurPlateau2/10;
if(temperature <= valeurTemp2)
{
strip.setPixelColor(13, 25,50,150);
strip.show();
}
}