#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <string.h>
#include "RTClib.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 5
//******************************declaration des variable de rot_encoder *******************************//
const int ENCODER_DT = 2;
const int ENCODER_CLK = 3;
const int ENCODER_BTN = 4;
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 stock;
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 ;
//*****************************************************************************************//
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"};
//*****************************************************************************************//
bool etat_btn_menu = false;
//***********************************************************************//
bool quiter = 0; char tab_don_plus[15][5][4];bool sauvgard = 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, 0xf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xf7, 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);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
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);
delay(1000); // Pause for 2 seconds
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
//*******************************affichage logo APEM******************************************//
//afichage_animation_apem();
//********************************************************************************************//
}
void loop() {
/*while(etat_btn_menu == false){
affich_date();
etat_btn_menu = etat_btn();
}
while (verif == false)
{
draw_clavier();
calc_pos_choix();
select_ch();
display.setCursor(76,7);
display.println(mot);
display.display();
}
*/
/* counter = 0;
while(1){
aff_menu();
//choix = counter;
} */
//manuel_mode();
//ajout_temps();
jour_travail();
/*while(out == false){
reglage_date_temps();
}
while(1){
affiche_info();
}*/
}
//**************************************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)
{verif = true;}
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(){
int m = 0;
while(digitalRead(btn_menu) == HIGH){
m++;
delay(500);
if(m >= 2)
return true;
}
return false;
}
bool etat_btn_select(){
int m = 0;
while(digitalRead(ENCODER_BTN) == LOW){
m++;
delay(500);
if(m >= 2)
return true;
}
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();
}
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(out == false){
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 :
out = true;
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;
}
else{
display.drawBitmap(39,26,epd_bitmap_on_off_12765554__1_,50,21,1);
automatic = false;
}
display.display();
delay(40);
if (etat_btn() == true)
out_manuel = true;
}
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(){
byte i = 0 ;
counter = 0;
//quiter = 0;
while( (i < 15) && (quiter == 0)){
if ((tab_don_plus[i][0] == "1" ) || (sauvgard == 1)){
i++;
sauvgard = 0;
goto skip;
}
display.clearDisplay();
display.setCursor(4, 4);
display.print("Temps ");
display.print(i);
display.display();
skip:
delay(40);
}
}