I am working with a tablet samsung tab A7 and an ESP 32. I am trying to switch serial screen if humidity of the room reach a certain level. I see that work because it is printed on the screen but do not switch screen and i do not why. It worked before i add a RFID check on a previous virtual screen but i do not work so i move the part about the humidity on an another and it doesnot work. Can someone explain me what is wrong?
#include <BME280I2C.h>
#include <Wire.h>
#include <ESP32Servo.h>
#include <RFID.h>
#include <SPI.h>
//#include <FastLED.h>
#define PIN_SG90 15 // Broche de sortie utilisée
#define SERIAL_BAUD 115200
#define LED_PIN 2
//#define NUM_LEDS 20
//#define DATA_PIN 15
//CRGB leds[NUM_LEDS];
#define SERIAL_BAUD 115200
#define PIN_RFID_RST 32
#define PIN_RFID_NSS 4
Servo sg90;
RFID rfid(PIN_RFID_NSS, PIN_RFID_RST);
unsigned char status;
unsigned char str[MAX_LEN];
int ValCarte;
int IDCarte[5] = {67,215,235,12,115};
int IDBadge[5] = {89,134,170,153,236};
BME280I2C bme;
void setup() {
prepare_serial();
prepare_RFID();
prepare_I2C();
prepare_BME();
//FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds,NUM_LEDS);
sg90.setPeriodHertz(50); // Fréquence PWM pour le SG90
sg90.attach(PIN_SG90, 500, 2400);
}
void loop() {
String message;
print_donnees_BME280(&Serial);
delay(10);
if(message.equals("Tartuffe") || message.equals("1898")){
servo();
}
//Bande_Led();
delay(10);
LectureCarte();
}
/*void Bande_Led (){
for (int i = 0; i<= 19; i++){
leds[i]=CRGB::Red;
FastLED.show();
delay(500);
}
}*/
void prepare_RFID(){
SPI.begin();
rfid.init();
}
void servo() {
for (int pos = 0; pos <= 180; pos += 1) {
sg90.write(pos);
delay(10);
}
// Rotation de 180° à 0°
for (int pos = 180; pos >= 0; pos -= 1) {
sg90.write(pos);
delay(10);
}
}
void prepare_I2C(){
Wire.begin(); //GPIO 22 et 21 par défaut
}
void prepare_serial(){
Serial.begin(SERIAL_BAUD);
while(!Serial) {} // Wait
}
void prepare_BME(){
while(!bme.begin())
{
Serial.println("Could not find BME280 sensor!");
delay(1000);
}
switch(bme.chipModel())
{
case BME280::ChipModel_BME280:
Serial.println("Found BME280 sensor! Success.");
break;
case BME280::ChipModel_BMP280:
Serial.println("Found BMP280 sensor! No Humidity available.");
break;
default:
Serial.println("Found UNKNOWN sensor! Error!");
}
}
//Fonction prise dans le tutoriel
void print_donnees_BME280(Stream* client)
{
float temp(NAN), hum(NAN), pres(NAN);
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_Pa);
bme.read(pres, temp, hum, tempUnit, presUnit);
//client->print(hum);
//client->print("% RH");
if (hum >= 60)
{
Serial.println("Ca marche BME \n");
}
}
void LectureCarte() {
String message;
if (rfid.findCard(PICC_REQIDL, str) == MI_OK) {
if (rfid.anticoll(str) == MI_OK) {
}
rfid.selectTag(str);
if (str[0] == IDCarte[0] && str[1] == IDCarte[1] && str[2] == IDCarte[2] && str[3] == IDCarte[3] && str[4] == IDCarte[4]){
Serial.println("Bonne carte");
}
if(str[0] == IDBadge[0]&& str[1] == IDBadge[1] && str[2] == IDBadge[2] && str[3] == IDBadge[3] && str[4] == IDBadge[4]){
Serial.println("Bon badge");
}
rfid.halt();
}
}