#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <string.h>
#include "RTClib.h"
#include <EEPROM.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define btn_menu 26
//******************************declaration des variable de rot_encoder *******************************//
const int ENCODER_DT = 33;
const int ENCODER_CLK = 25;
const int ENCODER_BTN = 32;
const int RELAY = 13;
volatile bool turnedCW = false;
volatile bool turnedCCW = false;
volatile bool lastWasCW = false;
volatile bool lastWasCCW = false;
volatile int counter0 = 0;
int counter = 0;
unsigned long debounceTime = 0;
const unsigned long DEBONCE_TO = 10;
//********************************ds variable de selection************************************//
double dep_y;
int x,y;
int selectDelay = 0;
bool clk = false;
bool boolselect = false;
int indexx = 0;
char message[20];
char mot[20];
bool verif = false;
int choix;
int stock;
bool choix_menu = false;
bool selection = false;
bool out = false;
bool automatic = true;bool out_manuel = false;
byte cpb = 0;byte lastButtonState = 0;byte select_choice_Mode = 0;
byte choice_add_time ;int choix_ajout_temp;bool etat_ajout_temps = false;int lastButtonState_2 = 0;
bool ledState = LOW;
//*****************************************************************************************//
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"};
//*****************************************************************************************//
bool etat_btn_menu = false;int oldValue = LOW;int oldValue_1 = HIGH;
//***********************************************************************//
;const int rows = 15;const int cols = 5; int tab_don_plus[rows][cols];bool sauvgard = 0;
//*********************************************************************//
int val_pos_plus_temps ;bool etat_val_pos_plus = false;int i;
bool test_1 = false;int beta;bool veriif_temp1 = false;bool veriif_temp2 = true;
bool veriif_temp3 = false;bool veriif_temp4 = false;unsigned long last_time_check_1 = 0;
//*************************************loogo_utiliser***************************************//
const uint8_t myBitmap[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7d, 0x2f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf9, 0x25, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xc0, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xa0, 0x01, 0x70, 0x00, 0x3e, 0x00, 0x7f, 0xfe, 0x07, 0xff, 0xf0, 0xfc, 0x00, 0x7e, 0x00,
0x03, 0x00, 0x00, 0x70, 0x00, 0x7f, 0x00, 0x7f, 0xff, 0x87, 0xff, 0xf1, 0xfe, 0x00, 0xfe, 0x00,
0x07, 0x00, 0x00, 0x38, 0x00, 0xff, 0x00, 0x7f, 0xff, 0xc7, 0xff, 0xf0, 0xfe, 0x01, 0xfe, 0x00,
0x06, 0x00, 0x00, 0x18, 0x00, 0xff, 0x80, 0x7f, 0xff, 0xc7, 0xff, 0xf0, 0xff, 0x01, 0xfe, 0x00,
0x07, 0x00, 0x00, 0x38, 0x01, 0xf7, 0xc0, 0x78, 0x07, 0xc7, 0x80, 0x00, 0xff, 0x03, 0xfe, 0x00,
0x0c, 0x00, 0x00, 0x08, 0x01, 0xe7, 0xc0, 0x78, 0x03, 0xc7, 0x80, 0x00, 0xf7, 0x83, 0xde, 0x00,
0x0e, 0x00, 0x00, 0x1c, 0x03, 0xe3, 0xe0, 0x78, 0x03, 0xc7, 0xff, 0xf0, 0xf7, 0xc7, 0x9e, 0x00,
0x0e, 0x00, 0x00, 0x1c, 0x03, 0xc1, 0xe0, 0x78, 0x07, 0xc7, 0xff, 0xf0, 0xf3, 0xcf, 0x9e, 0x00,
0x0e, 0x00, 0x00, 0x1c, 0x07, 0xc1, 0xf0, 0x7f, 0xff, 0xc7, 0xff, 0xf0, 0xf3, 0xef, 0x1e, 0x00,
0x0c, 0x00, 0x00, 0x08, 0x07, 0xff, 0xf0, 0x7f, 0xff, 0x87, 0x80, 0x00, 0xf1, 0xff, 0x1e, 0x00,
0x07, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xf8, 0x7f, 0xff, 0x07, 0x80, 0x00, 0xf1, 0xfe, 0x1e, 0x00,
0x07, 0x00, 0x00, 0x18, 0x1f, 0xff, 0xf8, 0x78, 0x00, 0x07, 0xc0, 0x10, 0xf0, 0xfe, 0x1e, 0x00,
0x07, 0x00, 0x00, 0x38, 0x1f, 0x00, 0x7c, 0x78, 0x00, 0x07, 0xff, 0xf8, 0xf0, 0xfc, 0x1e, 0x00,
0x03, 0x00, 0x00, 0x30, 0x3e, 0x00, 0x7c, 0x78, 0x00, 0x07, 0xff, 0xf9, 0xf0, 0x7c, 0x1e, 0x00,
0x03, 0xa0, 0x01, 0x70, 0x3e, 0x00, 0x3e, 0x78, 0x00, 0x07, 0xff, 0xf8, 0xf0, 0x38, 0x1e, 0x00,
0x01, 0xc0, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf8, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7d, 0x2f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3e, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t myBitmap1[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xc0, 0x00, 0x00, 0x3f, 0xe0, 0x00,
0x00, 0x7f, 0xf0, 0x00, 0x00, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xf8, 0x00,
0x00, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xf8, 0x00,
0x00, 0x7f, 0xf0, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x04, 0x00,
0x00, 0x0f, 0x06, 0x00, 0x01, 0xff, 0x66, 0x60, 0x07, 0xff, 0x7f, 0xe0, 0x0f, 0xff, 0x39, 0xc0,
0x1f, 0xfe, 0x30, 0xc0, 0x3f, 0xfc, 0xe0, 0xf0, 0x3f, 0xfc, 0xe0, 0xf0, 0x3f, 0xfe, 0x30, 0xc0,
0x3f, 0xff, 0x3f, 0xc0, 0x3f, 0xff, 0x7f, 0xe0, 0x3f, 0xff, 0x66, 0x40, 0x00, 0x00, 0x06, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
const unsigned char myBitmap2 [] PROGMEM = {
// 'page_1'
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
// 'calendrier (2)', 30x30px
const unsigned char epd_bitmap_calendrier__2_ [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x66, 0xee, 0x00, 0x3d, 0xbb, 0xbb, 0xc0,
0xc7, 0xfa, 0xaa, 0x20, 0x86, 0x66, 0x4c, 0x00, 0x80, 0x00, 0x00, 0x10, 0xf3, 0xff, 0xff, 0xf0,
0x80, 0x00, 0x00, 0x30, 0x80, 0x00, 0x00, 0x10, 0x9d, 0xee, 0x73, 0x90, 0x95, 0x2a, 0x54, 0x90,
0x9c, 0xce, 0x73, 0x10, 0x80, 0x00, 0x00, 0x00, 0x9c, 0xce, 0x0f, 0x80, 0x95, 0x2a, 0x30, 0x20,
0x9c, 0xee, 0x40, 0x10, 0x80, 0x00, 0x00, 0x08, 0x80, 0x00, 0x00, 0x04, 0x95, 0xe0, 0x04, 0x04,
0x95, 0x21, 0x07, 0x04, 0x9c, 0xc1, 0x05, 0x04, 0x80, 0x00, 0x02, 0x04, 0x7f, 0xfc, 0x80, 0x04,
0x00, 0x00, 0x80, 0x08, 0x00, 0x00, 0x40, 0x18, 0x00, 0x00, 0x20, 0x30, 0x00, 0x00, 0x18, 0xc0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'du-temps-en-plus (2)', 30x30px
const unsigned char epd_bitmap_du_temps_en_plus__2_ [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0x00, 0x00, 0x7f, 0xf8, 0x00,
0x01, 0xe0, 0x1e, 0x00, 0x03, 0x80, 0x07, 0x00, 0x07, 0x03, 0x03, 0x80, 0x0e, 0x03, 0x01, 0xc0,
0x0c, 0x03, 0x00, 0xc0, 0x18, 0x03, 0x00, 0x60, 0x18, 0x03, 0x00, 0x60, 0x30, 0x03, 0x00, 0x30,
0x30, 0x03, 0x00, 0x30, 0x30, 0x03, 0x00, 0x30, 0x30, 0x03, 0x00, 0x30, 0x30, 0x07, 0x00, 0x10,
0x30, 0x1c, 0x0f, 0x80, 0x30, 0x38, 0x3f, 0xc0, 0x30, 0x60, 0x70, 0xe0, 0x18, 0x40, 0x66, 0x70,
0x18, 0x00, 0xc6, 0x30, 0x0c, 0x00, 0xdf, 0xb0, 0x0e, 0x00, 0xdf, 0xb0, 0x07, 0x00, 0xc6, 0x30,
0x03, 0x80, 0xe6, 0x70, 0x01, 0xe0, 0x70, 0xe0, 0x00, 0x7e, 0x3f, 0xc0, 0x00, 0x1f, 0x1f, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'temps (2)', 30x30px
const unsigned char epd_bitmap_temps__2_ [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x01, 0xe0, 0x1e, 0x00,
0x03, 0x80, 0x07, 0x00, 0x06, 0x00, 0x01, 0x80, 0x0c, 0x00, 0x00, 0xc0, 0x18, 0x00, 0x00, 0x60,
0x18, 0x03, 0x00, 0x60, 0x30, 0x03, 0x00, 0x30, 0x30, 0x03, 0x00, 0x30, 0x60, 0x03, 0x00, 0x18,
0x60, 0x03, 0x00, 0x18, 0x60, 0x03, 0x00, 0x18, 0x60, 0x03, 0x00, 0x18, 0x60, 0x03, 0x80, 0x18,
0x00, 0x00, 0xc0, 0x18, 0x07, 0x80, 0x70, 0x18, 0x1f, 0xe0, 0x30, 0x18, 0x38, 0x70, 0x00, 0x30,
0x30, 0x30, 0x00, 0x30, 0x60, 0x18, 0x00, 0x60, 0x67, 0x98, 0x00, 0x60, 0x67, 0x98, 0x00, 0xc0,
0x60, 0x18, 0x01, 0x80, 0x30, 0x30, 0x07, 0x00, 0x38, 0x70, 0x1e, 0x00, 0x1f, 0xe3, 0xf8, 0x00,
0x07, 0x83, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'down-arrow_4687126 (2)', 10x10px
const unsigned char epd_bitmap_down_arrow_4687126__2_ [] PROGMEM = {
0x00, 0x00, 0x20, 0x00, 0x78, 0x00, 0x7e, 0x00, 0x7f, 0x00, 0x7f, 0x00, 0x7e, 0x00, 0x78, 0x00,
0x20, 0x00, 0x00, 0x00
};
// 'down-arrow_4687126 (1) (1)', 10x10px
const unsigned char epd_bitmap_down_arrow_4687126__1___1_ [] PROGMEM = {
0x00, 0x00, 0x01, 0x00, 0x07, 0x80, 0x1f, 0x80, 0x3f, 0x80, 0x3f, 0x80, 0x1f, 0x80, 0x07, 0x80,
0x01, 0x00, 0x00, 0x00
};
// 'b42faca5293a154390cc603dda8c8159', 30x30px
const unsigned char epd_bitmap_b42faca5293a154390cc603dda8c8159 [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x3f, 0xf0, 0x00, 0x00, 0xff, 0xfc, 0x00,
0x03, 0xff, 0xff, 0x00, 0x07, 0xff, 0xff, 0x80, 0x0f, 0xff, 0xff, 0xc0, 0x0f, 0xfe, 0x3f, 0xc0,
0x1f, 0xfc, 0x3f, 0xe0, 0x1f, 0xfc, 0x3f, 0xe0, 0x3f, 0xff, 0x7f, 0xf0, 0x3f, 0xff, 0xff, 0xf0,
0x3f, 0xf8, 0xff, 0xf0, 0x7f, 0xe0, 0x7f, 0xf8, 0x7f, 0xf8, 0x7f, 0xf8, 0x7f, 0xf8, 0x7f, 0xf8,
0x7f, 0xf8, 0x7f, 0xf8, 0x3f, 0xf8, 0xff, 0xf0, 0x3f, 0xf8, 0xff, 0xf0, 0x3f, 0xf0, 0xff, 0xf0,
0x1f, 0xf0, 0xff, 0xe0, 0x1f, 0xf0, 0xff, 0xe0, 0x0f, 0xf8, 0x3f, 0xc0, 0x0f, 0xff, 0xff, 0xc0,
0x07, 0xff, 0xff, 0x80, 0x03, 0xff, 0xff, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0x3f, 0xf0, 0x00,
0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'Untitled (3) (1)', 60x60px
const unsigned char epd_bitmap_Untitled__3___1_ [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
0xf0, 0x00, 0xcf, 0x99, 0xe3, 0x30, 0x00, 0xf0, 0xf3, 0xfc, 0xc0, 0x18, 0xe0, 0x73, 0xfc, 0xf0,
0xf7, 0xfe, 0xc0, 0x38, 0x6c, 0xf7, 0xfe, 0xf0, 0xf7, 0x0e, 0xce, 0x3e, 0x10, 0x37, 0x0e, 0xf0,
0xf6, 0x06, 0xcf, 0x7e, 0x10, 0x36, 0x06, 0xf0, 0xf6, 0x06, 0xfc, 0xe1, 0x8c, 0xf6, 0x06, 0xf0,
0xf6, 0x06, 0xfc, 0xe1, 0x8c, 0xf6, 0x06, 0xf0, 0xf6, 0x06, 0xfc, 0x07, 0x90, 0xf6, 0x06, 0xf0,
0xf7, 0x0e, 0xfc, 0x07, 0x10, 0xf7, 0x0e, 0xf0, 0xf7, 0xfe, 0xcc, 0x98, 0x13, 0xf7, 0xfe, 0xf0,
0xf3, 0xfc, 0xcc, 0x98, 0x13, 0xf3, 0xfc, 0xf0, 0xf0, 0x00, 0xcc, 0x99, 0x93, 0x30, 0x00, 0xf0,
0xff, 0xff, 0xc2, 0x00, 0x1c, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xc3, 0x00, 0x1c, 0xff, 0xff, 0xf0,
0xfe, 0x06, 0xcf, 0xf8, 0x7b, 0xc1, 0xe0, 0xf0, 0xfe, 0x06, 0xcf, 0xf8, 0x73, 0xc1, 0xe0, 0xf0,
0xfc, 0x1f, 0xc3, 0xdf, 0xef, 0xf0, 0x04, 0xf0, 0xf8, 0x1f, 0xc3, 0x8f, 0xef, 0xe0, 0x06, 0xf0,
0xf8, 0x00, 0xfc, 0x01, 0xff, 0x03, 0xe7, 0xf0, 0xfc, 0x00, 0x78, 0x01, 0xff, 0x03, 0xe7, 0xf0,
0xff, 0x9f, 0x30, 0xfe, 0x6f, 0xc0, 0x19, 0xf0, 0xfc, 0x00, 0x00, 0x70, 0x0f, 0x80, 0x00, 0xf0,
0xf8, 0x00, 0xcf, 0x21, 0x9f, 0x09, 0xe0, 0xf0, 0xf2, 0x11, 0x3c, 0x9e, 0x78, 0x02, 0x10, 0xf0,
0xf2, 0x19, 0x3c, 0x9e, 0x70, 0x02, 0x18, 0xf0, 0xf3, 0xf8, 0xc0, 0x87, 0xf3, 0x01, 0xff, 0xf0,
0xf3, 0xf8, 0xc0, 0x87, 0xf3, 0x01, 0xff, 0xf0, 0xf0, 0x67, 0x00, 0x80, 0x7f, 0xc2, 0x1f, 0xf0,
0xf0, 0x67, 0x00, 0x80, 0x7f, 0xc6, 0x1f, 0xf0, 0xf2, 0x06, 0x30, 0x19, 0xf3, 0xfe, 0x00, 0xf0,
0xf3, 0x04, 0x30, 0x19, 0xfb, 0xfe, 0x00, 0xf0, 0xf3, 0xe1, 0xff, 0x39, 0x9f, 0x38, 0x60, 0xf0,
0xf3, 0xe0, 0xe3, 0x36, 0x1b, 0x32, 0x07, 0xf0, 0xf3, 0xe0, 0xc3, 0x26, 0x13, 0x32, 0x07, 0xf0,
0xf2, 0x67, 0x3c, 0x21, 0x9c, 0x30, 0x78, 0xf0, 0xf2, 0x67, 0x3c, 0x21, 0x9c, 0x30, 0x78, 0xf0,
0xf2, 0x18, 0x0f, 0x19, 0x9f, 0x00, 0x67, 0xf0, 0xf6, 0x18, 0x0e, 0x19, 0xbf, 0x00, 0x67, 0xf0,
0xff, 0xff, 0xc0, 0x00, 0x70, 0x3e, 0x18, 0xf0, 0xff, 0xff, 0xc0, 0x00, 0x70, 0x3e, 0x18, 0xf0,
0xf0, 0x00, 0xf0, 0x26, 0x60, 0x32, 0x7f, 0xf0, 0xf3, 0xfc, 0xf8, 0x60, 0x60, 0x36, 0x3b, 0xf0,
0xf7, 0xfe, 0xff, 0xe0, 0x60, 0x3e, 0x19, 0xf0, 0xf7, 0x0e, 0xc1, 0xe0, 0x71, 0x00, 0x04, 0xf0,
0xf6, 0x06, 0xc0, 0xe0, 0x73, 0x00, 0x06, 0xf0, 0xf6, 0x06, 0xc0, 0x1f, 0xbc, 0x09, 0x87, 0xf0,
0xf6, 0x06, 0xc0, 0x1f, 0x9c, 0x09, 0x87, 0xf0, 0xf6, 0x06, 0xc3, 0xf8, 0x10, 0x00, 0x01, 0xf0,
0xf7, 0x0e, 0xc3, 0xf8, 0x18, 0x00, 0x01, 0xf0, 0xf7, 0xfe, 0xfc, 0x20, 0x1c, 0x02, 0x19, 0xf0,
0xf3, 0xfc, 0xfc, 0x70, 0x1c, 0x06, 0x1b, 0xf0, 0xf0, 0x00, 0xfc, 0xfe, 0x0c, 0xfe, 0x1f, 0xf0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0
};
const unsigned char epd_bitmap_back_5345072__3_ [] PROGMEM = {
0x00, 0x00, 0x3f, 0x80, 0x00, 0xc0, 0x00, 0x60, 0x00, 0x20, 0x10, 0x20, 0x30, 0x60, 0x70, 0xc0,
0x7f, 0x80, 0x60, 0x00, 0x30, 0x00, 0x00, 0x00
};
const unsigned char epd_bitmap_back_5345072__23_ [] PROGMEM = {
0xff, 0xf0, 0xc0, 0x70, 0xff, 0x30, 0xff, 0x90, 0xff, 0xd0, 0xef, 0xd0, 0xcf, 0x90, 0x8f, 0x30,
0x80, 0x70, 0x9f, 0xf0, 0xcf, 0xf0, 0xff, 0xf0
};
// 'tap_885624 (1)', 30x30px
const unsigned char epd_bitmap_tap_885624__1_ [] PROGMEM = {
0x00, 0x1f, 0xe0, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x01, 0xff, 0xfe, 0x00, 0x07, 0xff, 0xff, 0x80,
0x0f, 0xfc, 0x7f, 0xc0, 0x1f, 0xff, 0xbf, 0xe0, 0x1f, 0xe1, 0xdf, 0xe0, 0x3f, 0xcc, 0xcf, 0xf0,
0x7f, 0xd2, 0xc7, 0xf8, 0x7f, 0xc0, 0xcf, 0xf8, 0x7f, 0xc8, 0xff, 0xf8, 0xff, 0xe9, 0xff, 0xfc,
0xff, 0xe8, 0xff, 0xfc, 0xff, 0xe8, 0x0f, 0xfc, 0xff, 0xeb, 0x47, 0xfc, 0xff, 0x8f, 0x57, 0xfc,
0xff, 0xaf, 0xd7, 0xfc, 0xff, 0xaf, 0xf7, 0xfc, 0xff, 0xbf, 0xf7, 0xfc, 0x7f, 0xbf, 0xf7, 0xf8,
0x7f, 0xbf, 0xf7, 0xf8, 0x7f, 0x9f, 0xe7, 0xf8, 0x3f, 0xdf, 0xef, 0xf0, 0x1f, 0xcf, 0xcf, 0xe0,
0x1f, 0xe3, 0x1f, 0xe0, 0x0f, 0xf8, 0x7f, 0xc0, 0x07, 0xff, 0xff, 0x80, 0x01, 0xff, 0xfe, 0x00,
0x00, 0xff, 0xfc, 0x00, 0x00, 0x1f, 0xe0, 0x00
};
// 'on11-off_12765554 (1)', 50x21px
const unsigned char epd_bitmap_on_off_12765554__1_ [] PROGMEM = {
0x00, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x0f, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x38, 0xf0, 0x01, 0xc0,
0x00, 0x07, 0x00, 0x73, 0xfc, 0x03, 0xe3, 0x18, 0x03, 0x80, 0x67, 0x9e, 0x07, 0x73, 0x98, 0x01,
0x80, 0xe6, 0x06, 0x06, 0x33, 0x98, 0x01, 0xc0, 0xcc, 0x03, 0x06, 0x33, 0xd8, 0x00, 0xc0, 0xcc,
0x03, 0x06, 0x33, 0xd8, 0x00, 0xc0, 0xcc, 0x03, 0x06, 0x33, 0xf8, 0x00, 0xc0, 0xcc, 0x03, 0x06,
0x33, 0x78, 0x00, 0xc0, 0xce, 0x07, 0x06, 0x33, 0x78, 0x00, 0xc0, 0xe7, 0x0e, 0x06, 0x33, 0x38,
0x01, 0xc0, 0x63, 0xfc, 0x07, 0xf3, 0x38, 0x01, 0x80, 0x71, 0xf8, 0x03, 0xe3, 0x18, 0x03, 0x80,
0x38, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x0f, 0xff,
0xff, 0xff, 0xff, 0xfc, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
};
// 'on-off11_12765554 (2)', 50x20px
const unsigned char epd_bitmap_on_off_12765554__2_ [] PROGMEM = {
0x00, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x0f, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x30, 0x70, 0xfe, 0x7f,
0x03, 0xc3, 0x00, 0x70, 0xf8, 0xfe, 0x7f, 0x0f, 0xf3, 0x80, 0x61, 0xdc, 0xc0, 0x60, 0x1c, 0x39,
0x80, 0xe1, 0x8c, 0xc0, 0x60, 0x18, 0x19, 0xc0, 0xc1, 0x8c, 0xc0, 0x60, 0x30, 0x0c, 0xc0, 0xc1,
0x8c, 0xfc, 0x7e, 0x30, 0x0c, 0xc0, 0xc1, 0x8c, 0xfc, 0x7e, 0x30, 0x0c, 0xc0, 0xc1, 0x8c, 0xc0,
0x60, 0x30, 0x0c, 0xc0, 0xc1, 0x8c, 0xc0, 0x60, 0x38, 0x1d, 0xc0, 0x61, 0xdc, 0xc0, 0x60, 0x1c,
0x39, 0x80, 0x70, 0xf8, 0xc0, 0x60, 0x0f, 0xf3, 0x80, 0x30, 0x70, 0xc0, 0x60, 0x07, 0xe3, 0x00,
0x1c, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x07, 0xff,
0xff, 0xff, 0xff, 0xf8, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00
};
//******************************************************************************************//
void setup() {
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
pinMode(btn_menu, INPUT);
pinMode(ENCODER_DT, INPUT);
pinMode(ENCODER_CLK, INPUT);
attachInterrupt(digitalPinToInterrupt(ENCODER_DT), checkEncoder, CHANGE);
pinMode(ENCODER_BTN , INPUT_PULLUP);
pinMode(RELAY , OUTPUT);
//eepromToMatrice(tab_don_plus, rows);
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
//*******************************affichage logo APEM******************************************//
//afichage_animation_apem();
delay(1000); // Pause for 1 seconds
//********************************************************************************************//
}
void loop() {
affich_date();
etat_btn_menu = etat_btn();
if (automatic == true){
DateTime now = rtc.now();
if(( now.dayOfTheWeek() > 0) && ( now.dayOfTheWeek() < 6)){
active_chaine();
check_time_active();
}
}
else{
int buttonState = digitalRead(ENCODER_BTN);
// Vérifier si l'état du bouton est passé de LOW à HIGH
if (buttonState == LOW && lastButtonState_2 == HIGH) {
// Inverser l'état de la LED
ledState = !ledState;
digitalWrite(RELAY, ledState); // Mettre à jour la LED en fonction de son nouvel état
}
// Mettre à jour l'état précédent du bouton
lastButtonState_2 = buttonState;
}
while(etat_btn_menu == true){
draw_clavier();
calc_pos_choix();
select_ch();
display.setCursor(76,7);
display.println(mot);
display.display();
if(etat_btn() == true){
for (int i = 0; i < sizeof(message); i++) {
message[i] = '\0';
mot[i]= '\0';
}
indexx =0;
etat_btn_menu = false;
}
while(verif == true){
aff_menu();
choix = counter;
if(etat_btn_select() == true){
choix_menu = true;
}
if (etat_btn() == true){
verif = false;
etat_btn_menu = false;
}
switch(choix){
case 0 :
while(choix_menu == true){
reglage_date_temps();
}
break;
case 1 :
while(choix_menu == true){
ajout_temps();
choix_ajout_temp = counter;
switch(choix_ajout_temp){
case 0:
if(etat_btn_select() == true){
etat_ajout_temps = true;
}
i = 0;
while( (i < 15) && ( etat_ajout_temps == true )){
jour_travail();
fun_plus_temps();
}
break;
case 1 :
if(etat_btn_select() == true){
etat_ajout_temps = true;
}
while(etat_ajout_temps == true){
display.clearDisplay();
display.setCursor(2,20);
display.println("ce choix");
display.println(" ");
display.println("n'est pas");
display.println(" ");
display.println("active");
display.display();
if(etat_btn() == true){
etat_ajout_temps = false;
choix_ajout_temp = 1;
}
}
break;
case 2 :
if(etat_btn_select() == true){
choix_menu = false;
}
break;
}
}
break;
case 2 :
moveAndSortRows(tab_don_plus, rows);
x = verif_case_plein() - 1;
while(choix_menu == true){
Remove_temps(x);
}
break;
case 3 :
while(choix_menu == true){
manuel_mode();
}
break;
case 4 :
while(choix_menu == true){
affiche_info();
}
break;
}
}
}
}
//**************************************check_encoder**********************************//
void checkEncoder() {
if ((!turnedCW) && (!turnedCCW)) {
int pinA = digitalRead(ENCODER_CLK);
delayMicroseconds(1500); // Délai pour éliminer le bruit de lecture
int pinB = digitalRead(ENCODER_DT);
if (pinA == pinB) {
if (lastWasCW) {
turnedCW = true;
} else {
turnedCCW = true;
}
} else {
if (lastWasCCW) {
turnedCCW = true;
} else {
turnedCW = true;
}
}
}
}
//***************************************rotoray********************************************//
void r_encoder() {
if (turnedCW) {
counter0++;
if (counter0 >= 5) {
counter0 = 0;
counter++;
Serial.println("valeur: " + String(counter));
}
Serial.print("Turned CW: ");
Serial.println(counter0);
turnedCW = false;
lastWasCW = true;
debounceTime = millis();
}
else if (turnedCCW) {
counter0--;
if (counter0 <= -5) {
counter0 = 0;
counter--;
Serial.println("valeur: " + String(counter));
}
Serial.print("Turned CCW: ");
Serial.println(counter0);
turnedCCW = false;
lastWasCCW = true;
debounceTime = millis();
}
if ((millis() - debounceTime) > DEBONCE_TO) {
lastWasCW = false;
lastWasCCW = false;
}
}
//*******************************************************************************************//
void afichage_animation_apem() {
for (int i = 0 ; i<128; i++)
{
display.clearDisplay();
display.drawBitmap(4, 14, myBitmap, 123, 35, 1);
display.fillRect(i,12,128-i,40,BLACK);
display.display();
delay(20);//totale 3.25secondes
}
}
//*************************************************************************************//
void draw_clavier(){
display.clearDisplay();
//display.drawLine(x0, y0, x1, y1, couleur)
display.drawLine(46,1,46,63,WHITE);
display.drawLine(55,15,120,15,WHITE);
// Draw the bitmap at position (0, 0)
display.drawBitmap(8, 7, myBitmap1, 30, 30, 1);
display.setTextSize(1); // Taille du texte (1 = taille normale)
display.setCursor(8, 42); // Position du texte (x, y)
// Afficher le texte
display.println(F("Admin"));
display.setCursor(61,20);
display.println(F("1 2 3"));
display.setCursor(61,30);
display.println(F("4 5 6"));
display.setCursor(61,40);
display.println(F("7 8 9"));
display.setCursor(61,50);
display.println(F("* 0 #"));
}
void calc_pos_choix(){
r_encoder();
int maxcounter = 3;
if (counter > maxcounter)
counter = maxcounter;
int dep_x = counter ;
if (counter == 3)
{
dep_y++;
counter = 0;
}
if ((y > 48))
{
dep_y =0;
dep_x =0;
x = 54;
y = 18;
}
if( counter < 0 )
{
if(dep_y==0)
{dep_x = 2;counter = 2;dep_y=3;}
else{dep_y --;counter = 2;dep_x=2;}
}
x = 54 + (dep_x * 24);
y = 18 + (10* dep_y);
display.drawRect(x, y, 19, 11, WHITE);
if (selectDelay <= 5) {
selectDelay++;
}
if (digitalRead(ENCODER_BTN) == LOW) {
clk = true;
delay(150);
} else {
clk = false;
}
if ((selectDelay >= 3) && (clk == true)) {
selectDelay = 0;
boolselect = true;
} else {
boolselect = false;
}
}
void select_ch(){
if (boolselect == true)
{
switch(x)
{
case 54:
switch(y)
{
case 18 :
boolselect = false;
message[indexx] = '1';
mot[indexx]='*';
indexx++;
break;
case 28 :
boolselect = false;
message[indexx] = '4';
mot[indexx]='*';
indexx++;
break;
case 38 :
boolselect = false;
message[indexx] = '7';
mot[indexx]='*';
indexx++;
break;
case 48 :
boolselect = false;
indexx--;
if (indexx < 0) {
indexx = 0;
}
message[indexx] = ' ';
mot[indexx]=' ';
break;
}
break;
//****************************************
case 78:
switch(y)
{
case 18 :
boolselect = false;
message[indexx] = '2';
mot[indexx]='*';
indexx++;
break;
case 28 :
boolselect = false;
message[indexx] = '5';
mot[indexx]='*';
indexx++;
break;
case 38 :
boolselect = false;
message[indexx] = '8';
mot[indexx]='*';
indexx++;
break;
case 48 :
boolselect = false;
message[indexx] = '0';
mot[indexx]='*';
indexx++;
break;
}
break;
//*******************************************
case 102:
switch(y)
{
case 18 :
boolselect = false;
message[indexx] = '3';
mot[indexx]='*';
indexx++;
break;
case 28 :
boolselect = false;
message[indexx] = '6';
mot[indexx]='*';
indexx++;
break;
case 38 :
boolselect = false;
message[indexx] = '9';
mot[indexx]='*';
indexx++;
break;
case 48 :
boolselect = false;
int pass_1 = verif_password();
if(pass_1 == 1){
for (int i = 0; i < sizeof(message); i++) {
message[i] = '\0';
mot[i]= '\0';
}
indexx =0;
verif = true;
counter = 0;
}
else if (pass_1 == 0)
{
for (int i = 0; i < sizeof(message); i++)
{
message[i] = '\0';
mot[i]= '\0';
}
indexx =0;
verif = false;
}
break;
}
break;
}
}
}
int verif_password(){
char str1[] = "1234";
if (strcmp(str1, message) == 0) {
return 1;
} else {
display.fillRect(26, 10, 76, 42, BLACK);
display.drawRect(25, 9, 78, 44, WHITE);
display.setCursor(40,20);
display.println(F("Password"));
display.setCursor(37,34);
display.println(("Incorrect"));
display.display();
delay(1000);
return 0;
}
}
//****************************************************************************************//
void affich_date(){
display.clearDisplay();
DateTime now = rtc.now();
display.setTextSize(2);
display.setCursor(36,10);
if (now.hour()<10)
display.print("0");
display.print(now.hour());
display.print(":");
if (now.minute()<10)
display.print("0");
display.print(now.minute());
display.setTextSize(1);
display.setCursor(11,36);
display.print(daysOfTheWeek[now.dayOfTheWeek()]);
display.print(" ");
if (now.day()<10)
display.print("0");
display.print(now.day());
display.print("/");
if (now.month()<10)
display.print("0");
display.print(now.month());
display.print("/");
display.print(now.year());
display.display();
delay(40);
}
bool etat_btn(){
// Read the value of pin 8.
int newValue = digitalRead(btn_menu);
if(newValue != oldValue)
{
delay(40);
oldValue = newValue;
if(newValue == HIGH)
{
delay(300);
return true;
}
else
{
return false;
}
}
}
bool etat_btn_select(){
int newValue = digitalRead(ENCODER_BTN);
if(newValue != oldValue){
delay(40);
oldValue_1 = newValue;
if(newValue == LOW)
{
delay(300);
return true;
}
else
{
return false;
}
}
}
//****************************************************************************************//
void aff_menu(){
r_encoder();
if (counter < 0)
counter = 4;
if (counter > 4)
counter = 0;
display.clearDisplay();
display.setTextSize(1);
display.setCursor(52,2);
display.print("MENU");
display.drawLine(1, 13, 127, 13, SSD1306_WHITE);
display.drawBitmap( 108, 30 , epd_bitmap_down_arrow_4687126__2_, 10, 10 ,1);
display.drawBitmap( 10, 30 , epd_bitmap_down_arrow_4687126__1___1_, 10, 10 ,1);
switch(counter){
case 0 :
//*********************************************************//
display.drawBitmap(49, 19, epd_bitmap_calendrier__2_, 30, 30, 1);
display.setCursor(26,52);
display.print("Reglage temps");
break ;
//*********************************************************//
case 1 :
display.drawBitmap(49 , 19, epd_bitmap_du_temps_en_plus__2_, 30, 30, 1);
display.setCursor(31,52);
display.print("Ajout temps");
break ;
//***********************************************************//
case 2 :
display.drawBitmap(49 , 19, epd_bitmap_temps__2_ , 30, 30, 1);
display.setCursor(30,52);
display.print("Remove temps");
break ;
//*************************************************************//
case 3 :
display.drawBitmap(49 , 19, epd_bitmap_tap_885624__1_, 30, 30, 1);
display.setCursor(32,52);
display.print("mode manuel");
break ;
//***********************************************************//
case 4 :
display.drawBitmap(49 , 19, epd_bitmap_b42faca5293a154390cc603dda8c8159, 30, 30, 1);
display.setCursor(32,52);
display.print("Information");
break ;
}
display.display();
}
void affiche_info(){
display.clearDisplay();
display.drawBitmap(34,2,epd_bitmap_Untitled__3___1_,60,60,1);
display.display();
if (etat_btn() == true){
choix_menu = false;
}
}
void reglage_date_temps(){
DateTime now = rtc.now();
int jour = now.day() ;
int mois = now.month() ;
int annee = now.year() ;
int minute_r = now.minute() ;
int heur_r = now.hour();
while( choix_menu == true){
display.clearDisplay();
display.setTextSize(1);
display.setCursor(2,3);
display.print("Date :");
display.setCursor(2,33);
display.print("Temps :");
if ( selection == false){
stock = val_date(5,0);//***********************//
switch(stock){
case 0 :
display.drawLine(20, 26, 31, 26, SSD1306_WHITE);
break;
case 1 :
display.drawLine(49, 26, 61, 26, SSD1306_WHITE);
break;
case 2 :
display.drawLine(79, 26, 102, 26, SSD1306_WHITE);
break;
case 3 :
display.drawLine(44, 57, 55, 57, SSD1306_WHITE);
break;
case 4 :
display.drawLine(73, 57, 85, 57, SSD1306_WHITE);
break;
case 5 :
display.drawBitmap(107,3,epd_bitmap_back_5345072__23_,12,12,1);
break;
}
selection = etat_btn_select();
}
else{
//**********************************************************//
switch(stock){
case 0 :
display.drawLine(20, 26, 31, 26, SSD1306_WHITE);
jour = val_date(31,1);
break;
case 1 :
display.drawLine(49, 26, 61, 26, SSD1306_WHITE);
mois = val_date(12,1);
break;
case 2 :
display.drawLine(79, 26, 102, 26, SSD1306_WHITE);
annee = val_date(2100,2000);
break;
case 3 :
display.drawLine(44, 57, 55, 57, SSD1306_WHITE);
heur_r = val_date(23,0);
break;
case 4 :
display.drawLine(73, 57, 85, 57, SSD1306_WHITE);
minute_r = val_date(59,0);
break;
case 5 :
choix_menu = false;
selection = false;
rtc.adjust(DateTime(annee, mois, jour, heur_r, minute_r, 0));
break;
}
if (etat_btn() == true ){
selection = false;
counter = stock;
}
}
if (stock != 5)
display.drawBitmap(107,3,epd_bitmap_back_5345072__3_,12,12,1);
display.setCursor(20,18);
if (jour<10)
display.print("0");
display.print(jour);
display.print(" / ");
if (mois<10)
display.print("0");
display.print(mois);
display.print(" / ");
display.print(annee);
display.setCursor(44,48);
if (heur_r<10)
display.print("0");
display.print(heur_r);
display.print(" : ");
if (minute_r<10)
display.print("0");
display.print(minute_r);
display.display();
}
}
int val_date(int range , int min_range){
r_encoder();
if (counter > range)
counter = min_range;
if (counter < min_range)
counter = range;
return counter;
}
void manuel_mode(){
display.clearDisplay();
display.setCursor(3,3);
display.print("Mode manuel : ");
select_choice_Mode = digitalRead(ENCODER_BTN);
if (select_choice_Mode != lastButtonState) {
if (select_choice_Mode == HIGH) {
cpb++;
}
}
lastButtonState = select_choice_Mode ;
if(cpb == 0 || cpb > 1){
cpb = 0;
display.drawBitmap(39,26,epd_bitmap_on_off_12765554__2_,50,20,1);
automatic = true;
digitalWrite(RELAY, LOW);
}
else{
display.drawBitmap(39,26,epd_bitmap_on_off_12765554__1_,50,21,1);
automatic = false;
digitalWrite(RELAY, LOW);
}
display.display();
delay(40);
if (etat_btn() == true)
choix_menu = false;
}
void ajout_temps(){
display.clearDisplay();
display.setCursor( 30 , 4 );
display.print("Ajout temps");
val_date(2,0);
choice_add_time = counter;
display.fillRect(2,19 + (counter * 15),126,12,WHITE);
if (counter == 0)
{display.setTextColor(SSD1306_BLACK);}
else{display.setTextColor(SSD1306_WHITE);}
display.setCursor( 4 , 21 );
display.print("Les jours de travail");
if (counter == 1)
{display.setTextColor(SSD1306_BLACK);}
else{display.setTextColor(SSD1306_WHITE);}
display.setCursor( 4 , 36 );
display.print("Les jours de repos");
if (counter == 2)
{display.setTextColor(SSD1306_BLACK);}
else{display.setTextColor(SSD1306_WHITE);}
display.setCursor( 4 , 51 );
display.print("Retour");
display.setTextColor(SSD1306_WHITE);
display.display();
delay(40);
}
void jour_travail(){
if ((tab_don_plus[i][0]== 1 ) || (sauvgard == 1)){
i++;
sauvgard = 0;
goto skip;
}
display.clearDisplay();
display.setCursor(38, 4);
display.print("Temps ");
display.print(i);
display.setCursor(4 , 21);
display.print("Marche ");
//***************************************************/*/
if(tab_don_plus[i][1]<10)
display.print("0");
display.print(tab_don_plus[i][1]);
display.print(" : ");
if(tab_don_plus[i][2]<10)
display.print("0");
display.print(tab_don_plus[i][2]);
display.setCursor(4 , 36);
display.print("Arret ");
if(tab_don_plus[i][3]<10)
display.print("0");
display.print(tab_don_plus[i][3]);
display.print(" : ");
if(tab_don_plus[i][4]<10)
display.print("0");
display.print(tab_don_plus[i][4]);
display.setCursor(6 , 51);
display.print(" Enreg ");
display.print("Sortie");
//tab_don_plus[i][0] = "1" ;
skip:
delay(40);
}
void pos_plus_temps(){
switch(val_pos_plus_temps){
case 0 :
display.drawLine( 63, 30, 75, 30, SSD1306_WHITE);
break;
case 1 :
display.drawLine( 93, 30, 105, 30, SSD1306_WHITE);
break;
case 2 :
display.drawLine( 63, 45, 75, 45, SSD1306_WHITE);
break;
case 3 :
display.drawLine( 93, 45, 105, 45, SSD1306_WHITE);
break;
case 4 :
display.drawLine( 14, 61, 52, 61, SSD1306_WHITE);
break;
case 5 :
display.drawLine( 76, 61, 114, 61, SSD1306_WHITE);
break;
}
}
void fun_plus_temps(){
if(etat_btn_select() == true){
etat_val_pos_plus = true ;
}
if(etat_val_pos_plus == false ){
val_pos_plus_temps = val_date(5,0);
}
else{
reg_plus_temps();
}
pos_plus_temps();//*************************//
display.display();
}
void reg_plus_temps(){
pos_0:
switch(val_pos_plus_temps){
case 0 :
tab_don_plus[i][1] = val_date(23,0) ;
break;
case 1 :
tab_don_plus[i][2] = val_date(59,0) ;
break;
case 2 :
tab_don_plus[i][3] = val_date(23,0) ;
break;
case 3 :
tab_don_plus[i][4] = val_date(59,0) ;
break;
case 4 :
if(tab_don_plus[i][1]>tab_don_plus[i][3]){
val_pos_plus_temps = 0;
counter = val_pos_plus_temps;
goto pos_0;
}
if(tab_don_plus[i][1] == tab_don_plus[i][3] && tab_don_plus[i][2] >= tab_don_plus[i][4] ){
val_pos_plus_temps = 1;
counter = val_pos_plus_temps;
goto pos_0;
}
etat_val_pos_plus = false;
sauvgard = 1 ;
counter = val_pos_plus_temps;
tab_don_plus[i][0] = 1 ;
break;
case 5 :
moveAndSortRows(tab_don_plus, rows);
clearEEPROM();
matriceToEEPROM(tab_don_plus, rows);
etat_ajout_temps = false ;
choix_ajout_temp = 1;
etat_val_pos_plus = false;
break;
}
if ((val_pos_plus_temps == 0 || val_pos_plus_temps == 1 || val_pos_plus_temps == 2 || val_pos_plus_temps == 3) && (etat_btn() == true ) )
{etat_val_pos_plus = false;
counter = val_pos_plus_temps ;}
}
//********************///
int verif_case_plein(){
int k=0;
for(int j=0;j<15;j++){
if(tab_don_plus[j][0] == 1)
k++;
}
return k;
}
void Remove_temps(int b){
if(b != (-1)){
int k = val_date(b , 0);
int valll = 0;
pos_22 :
display.clearDisplay();
display.setCursor(38, 4);
display.print("Temps ");
display.print(k);
display.setCursor(4 , 21);
display.print("Marche ");
if(tab_don_plus[k][1]<10)
display.print("0");
display.print(tab_don_plus[k][1]);
display.print(" : ");
if(tab_don_plus[k][2]<10)
display.print("0");
display.print(tab_don_plus[k][2]);
display.setCursor(4 , 36);
display.print("Arret ");
if(tab_don_plus[k][3]<10)
display.print("0");
display.print(tab_don_plus[k][3]);
display.print(" : ");
if(tab_don_plus[k][4]<10)
display.print("0");
display.print(tab_don_plus[k][4]);
if(etat_btn() == true){
x = verif_case_plein() - 1;
if(b != x){
Serial.println("ohhoooo");
clearEEPROM();
matriceToEEPROM(tab_don_plus, rows);
choix_menu = false;
}else{
choix_menu = false;
Serial.println("ma fama chy");
}
}
if (etat_btn_select() == true){test_1 = true; valll = counter ;delay(40);}
if (test_1 == true){
r_encoder();
display.fillRect(20,10,88,44,WHITE);
display.setTextColor(SSD1306_BLACK);
display.setCursor(43 , 38);
display.print("Remove");
display.drawLine(42, 46, 78, 46, BLACK);
display.setTextColor(SSD1306_WHITE);
if(counter != valll){
for(int rm = 0 ;rm < cols ;rm++){
tab_don_plus[k][rm] = 0;
}
moveAndSortRows(tab_don_plus, rows);
test_1 = false;
counter = k;
}
if(etat_btn() == true){test_1 = false;counter = k;}
}
display.display();
if (test_1 == true){goto pos_22;}}
else{
display.clearDisplay();
display.setCursor(43,22);
display.setTextSize(2);
display.print("none");
display.setTextSize(1);
display.display();
if(etat_btn() == true){choix_menu = false;}
}
}
//*********************tri des données************************************************//
void swapRows(int matrice[][cols], int row1, int row2) {
for (int w = 0; w < cols; w++) {
int temp = matrice[row1][w];
matrice[row1][w] = matrice[row2][w];
matrice[row2][w] = temp;
}
}
void moveAndSortRows(int matrice[][cols], int rows) {
// Étape 1: Déplacer les lignes où matrice[i][0] == 1 en haut
int index = 0;
for (int w = 0; w < rows; w++) {
if (matrice[w][0] == 1) {
swapRows(matrice, w, index);
index++;
}
}
for (int w = 1; w < index; w++) {
int keyRow = w;
for (int f = w - 1; f >= 0; f--) {
bool shouldSwap = false;
for (int k = 1; k < cols; k++) {
if (matrice[f][k] < matrice[f + 1][k]) {
shouldSwap = true;
break;
} else if (matrice[f][k] > matrice[f + 1][k]) {
break;
}
}
if (shouldSwap) {
swapRows(matrice, f, f + 1);
}
}
}
}
//******************************************************************************************//
void saveToEEPROM(int startAddr, const char* data) {
int k = 0;
while (data[k] != '\0') {
EEPROM.write(startAddr + k, data[k]);
k++;
}
EEPROM.write(startAddr + i, '\0'); // Ajouter le caractère null de fin
}
void matriceToEEPROM(int matrice[][cols], int rows) {
int eepromAddr = 0; // Adresse de départ dans l'EEPROM
for (int k = 0; k < rows; k++) {
char buffer[50]; // Assurez-vous que ce buffer est suffisamment grand
sprintf(buffer, "%d/%d/%d/%d/%d", matrice[k][0], matrice[k][1], matrice[k][2], matrice[k][3], matrice[k][4]);
saveToEEPROM(eepromAddr, buffer);
// Incrémenter l'adresse de départ pour la prochaine ligne
eepromAddr += strlen(buffer) + 1; // +1 pour le caractère null
}
}
//*****************************************************************************************//
void loadFromEEPROM(int startAddr, char* buffer, int maxLen) {
int k = 0;
char ch;
while (true) {
ch = EEPROM.read(startAddr + k);
if (ch == '\0' || k >= maxLen - 1) { // Arrêter à la fin de la chaîne ou si le buffer est plein
break;
}
buffer[k] = ch;
k++;
}
buffer[k] = '\0'; // Ajouter le caractère null de fin
}
void eepromToMatrice(int matrice[][cols], int rows) {
int eepromAddr = 0; // Adresse de départ dans l'EEPROM
for (int k = 0; k < rows; k++) {
char buffer[50]; // Assurez-vous que ce buffer est suffisamment grand pour contenir la chaîne
loadFromEEPROM(eepromAddr, buffer, sizeof(buffer));
// Convertir la chaîne en valeurs entières et les insérer dans la matrice
sscanf(buffer, "%d/%d/%d/%d/%d", &matrice[k][0], &matrice[k][1], &matrice[k][2], &matrice[k][3], &matrice[k][4]);
// Incrémenter l'adresse de départ pour la prochaine ligne
eepromAddr += strlen(buffer) + 1; // +1 pour le caractère null
}
}
//*****************************************************************************************//
void clearEEPROM() {
for (int i = 0; i < 250; i++) {
EEPROM.write(i, 0xFF); // Écrire 0xFF à chaque adresse (effacement)
}
}
//******************************************************************************************//
void active_chaine(){
DateTime now = rtc.now();
if (veriif_temp2 == true){
int verif_case = verif_case_plein();
for(int v = 0 ; v < verif_case ; v++){
if(tab_don_plus[v][1] == now.hour() && tab_don_plus[v][2]>= now.minute()){
beta = v;
veriif_temp1 = true;
veriif_temp2 = false;
break;
}
}
}
}
//********************************************************************************************//
void check_time_active(){
DateTime now = rtc.now();
if((millis() - last_time_check_1) >= 40000){
if (veriif_temp1 == true){
if(tab_don_plus[beta][2] <= now.minute()){
digitalWrite(RELAY , HIGH);
veriif_temp1 = false;
veriif_temp3 = true;
}
}
else if(veriif_temp3 == true){
if(tab_don_plus[beta][3] == now.hour()){
veriif_temp4 = true;
veriif_temp3 = false;
}
}
else if(veriif_temp4 == true){
if(tab_don_plus[beta][4] >= now.minute()){
digitalWrite(RELAY , LOW);
veriif_temp4 = false;
veriif_temp2 = true;
}
}
Serial.println("hani lahnee");
last_time_check_1 = millis();
}
}Loading
ssd1306
ssd1306