// Programme de Michael Bureau 2258226
#define WOKWI
// Differente bibliotheques utiliser pour le fonctionnement du programme
#include "SHT31.h"
#include "DHT.h"
#include "Streaming.h"
#include <Adafruit_NeoPixel.h>
#include "Wire.h"
// Les pins utilises
#define BOUTON 2
#define POT A3
#define DHTPIN 7
#define PIN2 3
#define PIN 2
// Temps pour le delay
#define DEMI_SEC 500
// Pour la temperature
#define TEMPERATURE_DE_BASE 24
#define TEMPERATURE_PALIER 0.75
// Les pixels pour le LED ring
#define PIXEL_ROUGE 245,22,26
#define PIXEL_BLEU 80,106,148
#define NUMPIXELS 10
#define LUMINOSITE 50
// Dimensions du LCD
#define LARGEUR_LCD 20
#define HAUTEUR_LCD 4
#define PREMIERE_LIGNE 0
#define DEUXIEME_LIGNE 1
// Differentes positions de l'affichage sur le LCD
#define POS_TEMP 14
#define POS_UN_ESPACE 11
#define POS_DEUX_ESPACES 9
#define POS_POT 8
#define POS_P 6
#define POS_R 0
#define POS_T 12
#define POS_BL 0
#define POS_RG 9
// Espaces pour effacer l'ancienne valeur du pot
#define DEUX_ESPACES " "
#define UN_ESPACE " "
#ifdef WOKWI // Pour la compabilite entre IDE et Wokwi
DHT capteurTemperature(DHTPIN, DHT22);
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, LARGEUR_LCD, HAUTEUR_LCD);
#else
#include "rgb_lcd.h"
rbg_lcd lcd;
SHT31 capteurTemperature;
#endif
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
Serial << "Debut du programme" ;
capteurTemperature.begin();
lcd.begin(LARGEUR_LCD ,HAUTEUR_LCD);
capteurTemperature.begin();
#ifdef DEBUG
Serial << "Temperature de depart: " << capteurTemperature.getTemperature() << endl;
#endif
// L'affichage du LCD
lcd.setCursor(POS_P ,PREMIERE_LIGNE);
lcd.print("P:");
lcd.setCursor(POS_R,PREMIERE_LIGNE);
lcd.print("R:");
lcd.setCursor(POS_BL,DEUXIEME_LIGNE);
lcd.print("BL :");
lcd.setCursor(POS_RG,DEUXIEME_LIGNE);
lcd.print("RG :");
lcd.setCursor(POS_T,PREMIERE_LIGNE);
lcd.print("T:");
#ifdef DEBUG
Serial << "Temp. = " << temperature << " ,NB pixels rouges = " << (nbPixelsRouges) << endl;
delay(DEMI_SEC );
#endif
// Etais incappable de faire fonction le LED ring
pixels.begin();
pixels.clear();
pixels.setBrightness(LUMINOSITE);
// Allumer le LED ring
for(int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(PIXEL_BLEU));
}
pixels.show();
}
void loop() {
uint32_t couleur;
// Definition des valeurs, le pot et le LED ring et le bouton
int valeurDuPot = (map(analogRead(A3), 0, 1023, 0, 10));
float temperature = capteurTemperature.readTemperature();
int valeurPot = analogRead(POT);
int etatBouton = digitalRead(BOUTON);
static int compteurBouton;
int nbPixelsRouges = (temperature - TEMPERATURE_DE_BASE) / TEMPERATURE_PALIER;
// Affichage des va;eur sur le LCD
lcd.setCursor(POS_POT, PREMIERE_LIGNE);
lcd.print(valeurPot);
if (valeurPot < 10) // <---
{
lcd.setCursor(POS_DEUX_ESPACES,PREMIERE_LIGNE);
lcd.print(DEUX_ESPACES);
}
if (valeurPot < 1000) // Valeur ne restait pas bien afficher avec trois espaces, donc deux if on ete ajouter
{ // pour dire quand afficher les espaces pour effacer l'ancien affichage
lcd.setCursor(POS_UN_ESPACE,PREMIERE_LIGNE);
lcd.print(UN_ESPACE);
}
lcd.setCursor(POS_TEMP,PREMIERE_LIGNE);
lcd.print(temperature);
#ifdef DEBUG
Serial << "Temp. = " << temperature << " ,NB pixels rouges = " << (nbPixelsRouges) << endl;
delay(DEMI_SEC );
#endif
// Etais incappable de faire fonction le LED ring
for (int pixelCourant = NUMPIXELS; pixelCourant >= 0; pixelCourant--) {
couleur = pixelCourant < (NUMPIXELS - nbPixelsRouges) ? pixels.Color(PIXEL_BLEU) : pixels.Color(PIXEL_ROUGE);
pixels.setPixelColor(pixelCourant, couleur);
}
pixels.show();
}