1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include <Arduino.h>
#include <GxEPD2_BW.h>
#include <U8g2_for_Adafruit_GFX.h>
#include "affichage.h"
#define ENABLE_GxEPD2_display 0
#define SCREEN_WIDTH 212
#define SCREEN_HEIGHT 104
#define Large 7 // For best results use odd numbers
#define Small 3 // For best results use odd numbers
GxEPD2_BW<GxEPD2_213_BN, GxEPD2_213_BN::HEIGHT> display(GxEPD2_213_BN(/*CS=5*/ 5, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
#define pinVb 35 //* mesure BATT
String(affichdate);
String(affichHeure);
//#########################################################################################
void InitialiseDisplay() {
display.init(115200, true, 2, false);
display.setRotation(1); // Use 1 or 3 for landscape modes
u8g2Fonts.begin(display); // connect u8g2 procedures to Adafruit GFX
u8g2Fonts.setFontMode(1); // use u8g2 transparent mode (this is default)
u8g2Fonts.setFontDirection(0); // left to right (this is default)
u8g2Fonts.setForegroundColor(GxEPD_BLACK); // apply Adafruit GFX color
u8g2Fonts.setBackgroundColor(GxEPD_WHITE); // apply Adafruit GFX color
u8g2Fonts.setFont(u8g2_font_helvB10_tf); // Explore u8g2 fonts from here: https://github.com/olikraus/u8g2/wiki/fntlistall
display.fillScreen(GxEPD_WHITE);
display.setFullWindow();
}
//#########################################################################################
void drawString(int x, int y, String text, alignmentType alignment) {
int16_t x1, y1; //the bounds of x,y and w and h of the variable 'text' in pixels.
uint16_t w, h;
display.setTextWrap(false);
display.getTextBounds(text, x, y, &x1, &y1, &w, &h);
if (alignment == RIGHT) x = x - w;
if (alignment == CENTER) x = x - w / 2;
//if (alignment == LEFT) x = x + w ;
u8g2Fonts.setCursor(x, y + h);
u8g2Fonts.print(text);
}
//#########################################################################################
void DisplayAstronomySection(int x, int y) {
//display.drawRect(x+5, y+85 , 220, 25, GxEPD_BLACK);
display.drawRect(x, y+85 , 240, 25, GxEPD_BLACK);
u8g2Fonts.setFont(u8g2_font_helvB08_tf);
drawString(x+5,y+95, affichalarme, LEFT);
display.display(false); // Full screen update mode
}
//#########################################################################################
void Draw_Heading_Section() {
u8g2Fonts.setFont(u8g2_font_helvB08_tf);
drawString(2, 1, affichdate+" "+affichHeure, LEFT);
//display.drawLine(0, 11, 200, 11, GxEPD_BLACK);
}
//#########################################################################################
void DrawBattery(int x, int y) {
if (voltage > 1 ) { // Only display if there is a valid reading
display.drawRect(x + 15, y - 12, 19, 10, GxEPD_BLACK);
display.fillRect(x + 34, y - 10, 2, 5, GxEPD_BLACK);
display.fillRect(x + 17, y - 10, 15 * percentage / 100.0, 6, GxEPD_BLACK);
drawString(x + 60, y - 11, String(percentage) + "%", RIGHT);
}
}
//#########################################################################################
void DrawPanneaux(int x, int y){
display.drawRect(x, y, x+184,y+60, GxEPD_BLACK);
//Panneau droit
display.drawRect(x+2, y+2, x+40,y+56, GxEPD_BLACK); // P11
display.drawRect(x+47, y+2, x+40,y+56, GxEPD_BLACK); // P12
drawString(x + 23, y+27, "P1", CENTER);
display.fillRect(x + 93, y, 3, 75, GxEPD_BLACK);
//Panneau gauche
display.drawRect(x+98, y+2, x+40,y+56, GxEPD_BLACK); // P22
display.drawRect(x+142, y+2, x+40,y+56, GxEPD_BLACK); // P21
drawString(x + 164, y+27, "P2", CENTER);
if (!P1) {
display.fillRoundRect(x+49, y+4, x+36, y+52 ,4, GxEPD_BLACK);
}else{
display.fillRoundRect(x+4, y+4, x+36, y+52 ,4, GxEPD_BLACK);
}
if (!P2) {
display.fillRoundRect(x+100, y+4, x+36, y+52,4, GxEPD_BLACK);
}else{
display.fillRoundRect(x+144, y+4, x+36, y+52,4, GxEPD_BLACK);
}
}
//#########################################################################################
void Draw_Temp_Hum_Section(int x, int y){
//sensors_event_t humidity, temp;
//aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
//Serial.print("Temperature: "); Serial.print(temp.temperature,1); Serial.println(" degrees C");
//Serial.print("Humidity: "); Serial.print(humidity.relative_humidity,0); Serial.println("% rH");
display.drawRect(x, y,x+10,y+60, GxEPD_BLACK);
display.drawLine(x, y+36, x+60, y+36, GxEPD_BLACK);
u8g2Fonts.setFont(u8g2_font_helvB18_tf);
//drawString(210,35, String(temp.temperature,0)+"c", CENTER);
drawString(210,35, String(AHT_Temp,0)+"c", CENTER);
//drawString(210,70, String(humidity.relative_humidity,0)+"%", CENTER);
drawString(210,70, String(AHT_Humidite,0)+"%", CENTER);
delay(500);
}
void full_sreeen(){
display.display(false); // Full screen update mode
}
void powerOff(){
display.powerOff();
} |
Partager