IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

Initialisation WeActStudio E-paper 2.9 inch [Arduino ESP32]


Sujet :

Arduino

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    988
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 988
    Par défaut Initialisation WeActStudio E-paper 2.9 inch
    Bonjour à tous

    je partage aujourd'hui mon petit souci concernant la mise en œuvre d'une carte d'affichage 2.9 de WeActStudio comme suit
    ESP32 CS(SS)=27,SCL=18,SDA=23,BUSY=13,RES=12,DC=14

    en effet

    si j'utilise ce programme de test sur l'ESP32:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
     
    /* ESP Weather Display using an EPD 2.9" Display, obtains data from Open Weather Map, decodes it and then displays it.
      ####################################################################################################################################
    */
     
    #include "owm_credentials.h"
    #include <ArduinoJson.h>     // https://github.com/bblanchon/ArduinoJson
    #include <WiFi.h>            // Built-in
    #include "time.h"
    #include <SPI.h>
    #define  ENABLE_GxEPD2_display 0
    #include <GxEPD2_BW.h>
    //#include <GxEPD2_3C.h>
    #include <U8g2_for_Adafruit_GFX.h>
    #include "forecast_record.h"
     
    //#include "lang.h"                     // Localisation (English)
    //#include "lang_cz.h"                // Localisation (Czech)
    //#include "lang_es.h"                // Localisation (Spanish)
    #include "lang_fr.h"                // Localisation (French)
    //#include "lang_gr.h"                // Localisation (German)
    //#include "lang_it.h"                // Localisation (Italian)
    //#include "lang_nl.h"                // Localisation (Dutch)
    //#include "lang_no.h"                // Localisation (Norwegian)
    //#include "lang_pl.h"                // Localisation (Polish)
    //#include "lang_pt.h"                // Localisation (Portugese)
     
    #define SCREEN_WIDTH   296
    #define SCREEN_HEIGHT  128
     
    enum alignmentType {LEFT, RIGHT, CENTER};
     
    // Connections 
    /*
    static const uint8_t EPD_BUSY = 3;  // to EPD BUSY
    static const uint8_t EPD_CS   = 7;  // to EPD CS
    static const uint8_t EPD_RST  = 2; // to EPD RST
    static const uint8_t EPD_DC   = 1; // to EPD DC
    static const uint8_t EPD_SCK  = 4; // to EPD CLK
    static const uint8_t EPD_MISO = 5; // Master-In Slave-Out not used, as no data from display
    static const uint8_t EPD_MOSI = 6; // to EPD DIN
    */
    static const uint8_t EPD_BUSY = 1;  // to EPD BUSY
    static const uint8_t EPD_CS   = 4;  // to EPD CS
    static const uint8_t EPD_RST  = 2; // to EPD RST
    static const uint8_t EPD_DC   = 3; // to EPD DC
    static const uint8_t EPD_SCK  = 5; // to EPD CLK
     
     
     
     
     
    // ESP32 CS(SS)=27,SCL=18,SDA=23,BUSY=13,RES=12,DC=14
    GxEPD2_BW<GxEPD2_290_T94, GxEPD2_290_T94::HEIGHT> display(GxEPD2_290_T94(/*CS=5*/ 27, /*DC=*/ 14, /*RST=*/ 12, /*BUSY=*/ 13)); // GDEM029T94 128x296, SSD1680
     
    U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;  // Select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
    // Using fonts:
    // u8g2_font_helvB08_tf
    // u8g2_font_helvB10_tf
    // u8g2_font_helvB12_tf
    // u8g2_font_helvB14_tf
    // u8g2_font_helvB18_tf
    // u8g2_font_helvB24_tf
     
     
     
    bool    LargeIcon = true, SmallIcon = false;
    #define Large 7    // For best results use odd numbers
    #define Small 3    // For best results use odd numbers
    String  time_str, date_str, ForecastDay; // strings to hold time and date
    int     wifi_signal, CurrentHour = 0, CurrentMin = 0, CurrentSec = 0;
    long    StartTime = 0;
     
    //################ PROGRAM VARIABLES and OBJECTS ##########################################
    #define max_readings 25 // In groups of 3-hours (3-days = 3 x 8 = 24)
    Forecast_record_type  WxConditions[1];
    Forecast_record_type  WxForecast[max_readings];
     
    #include <common.h>
     
    float pressure_readings[max_readings]    = {0};
    float temperature_readings[max_readings] = {0};
    float humidity_readings[max_readings]    = {0};
    float rain_readings[max_readings]        = {0};
    float snow_readings[max_readings]        = {0};
     
    long SleepDuration = 30; // Temps de sommeil en minutes, aligné sur la limite de la minute la plus proche, donc si 30, la mise à jour se fera toujours à 00 ou 30 heures passées.
    int  WakeupHour    = 7;  // Ne pas se réveiller avant 07h00 pour économiser la batterie
    int  SleepHour     = 23; // Mise en veille après (23+1) 00:00 pour économiser la batterie
     
    typedef struct { // For current Day and Day 1, 2, 3, etc
      String Time;
      float  High;
      float  Low;
    } HL_record_type;
     
    HL_record_type  HLReadings[max_readings];
     
    // Mesure Batterie...............................
    #define pinVb                35                  //* mesure BATT                                 */
    #define VccMin               3.2                 //* Niveau minimum attendu de BAT, en Volts     */
    #define VccMax               4.2                 //* Niveau maximum attendu de BAT, en Volts     */
    #define VccRange             VccMax - VccMin        
    const float Ratio          = 100.0 ;             // Eviter les divisions par la suite
     
    //#########################################################################################
    void setup() {
      StartTime = millis();
      //Serial.begin(115200);
      display.init(115200, true, 2, false);
      //while (!Serial);
      //Serial.println(__FILE__);
      if (StartWiFi() == WL_CONNECTED && SetupTime() == true) {
        bool WakeUp = false;
        if (WakeupHour > SleepHour)
          WakeUp = (CurrentHour >= WakeupHour || CurrentHour <= SleepHour);
        else
          WakeUp = (CurrentHour >= WakeupHour && CurrentHour <= SleepHour);
        if (WakeUp) {
          InitialiseDisplay(); // Give screen time to initialise by getting weather data!
          byte Attempts = 1;
          bool RxWeather = false, RxForecast = false;
          WiFiClient client;   // wifi client object
          while ((RxWeather == false || RxForecast == false) && Attempts <= 2) { // Try up-to 2 time for Weather and Forecast data
            if (RxWeather  == false) RxWeather  = obtain_wx_data(client, "weather");
            if (RxForecast == false) RxForecast = obtain_wx_data(client, "forecast");
            Attempts++;
          }
          if (RxWeather && RxForecast) { // Only if received both Weather or Forecast proceed
            GetHighsandLows();;
            StopWiFi(); // Reduces power consumption
            DisplayWeather();
            display.display(false); // Full screen update mode
          }
        }
      }
      BeginSleep();
    }
    //#########################################################################################
    void loop() { // this will never run!
    }
    //#########################################################################################
    void BeginSleep() {
      display.powerOff();
      long SleepTimer = (SleepDuration * 60 - ((CurrentMin % SleepDuration) * 60 + CurrentSec)); //Some ESP32 are too fast to maintain accurate time
      esp_sleep_enable_timer_wakeup((SleepTimer + 20) * 1000000LL); // Added +20 seconnds to cover ESP32 RTC timer source inaccuracies
    #ifdef BUILTIN_LED
      pinMode(BUILTIN_LED, INPUT); // If it's On, turn it off and some boards use GPIO-5 for SPI-SS, which remains low after screen use
      digitalWrite(BUILTIN_LED, HIGH);
    #endif
      Serial.println("Entering " + String(SleepTimer) + "-secs of sleep time");
      Serial.println("Awake for : " + String((millis() - StartTime) / 1000.0, 3) + "-secs");
      Serial.println("Starting deep-sleep period...");
      esp_deep_sleep_start();  // Sleep for e.g. 30 minutes
    }
    //#########################################################################################
    void DisplayWeather() {             // 2.9" e-paper display is 296x128 resolution
      UpdateLocalTime();
      Draw_Heading_Section();           // Tligne de l'afficheur
      Draw_Main_Weather_Section();      // Partie centrale de l'écran pour la localisation, la température, le bulletin météo, le symbole Wx et la direction du vent.
      int Forecast = 2, Dposition = 0;
      String StartTime  = "08:00" + String((Units == "M" ? "" : "a"));
      String MidTime    = "09:00" + String((Units == "M" ? "" : "a"));
      String FinishTime = "10:00" + String((Units == "M" ? "" : "a"));
      do {
        String Ftime = ConvertUnixTime(WxForecast[Forecast].Dt + WxConditions[0].Timezone).substring(0, (Units == "M" ? 5 : 6));
        if (Ftime == StartTime || Ftime == MidTime || Ftime == FinishTime) {
          DisplayForecastWeather(18, 104, Forecast, Dposition, 57); // Coordonnées x,y, numéro de prévision, position, largeur de l'espacement
          Dposition++;
        }
        Forecast++;
      } while (Forecast < max_readings);
      DrawBattery(160, 12);
    }
    //#########################################################################################
    void Draw_Heading_Section() {
      u8g2Fonts.setFont(u8g2_font_helvB08_tf);
      drawString(27, 15, City, CENTER);
      drawString(2, 1, time_str + "   " + date_str, LEFT);
      display.drawLine(0, 11, 150 + (Units == "I"?15:0), 11, GxEPD_BLACK);
    }
    //#########################################################################################
    void DisplayForecastWeather(int x, int y, int forecast, int Dposition, int fwidth) {
      GetForecastDay(WxForecast[forecast].Dt);
      x += fwidth * Dposition;
      DisplayConditionsSection(x + 10, y, WxForecast[forecast].Icon, SmallIcon);
      u8g2Fonts.setFont(u8g2_font_helvB08_tf);
      drawString(x + 8, y - 24, ForecastDay, CENTER);
      drawString(x + 18, y + 12, String(HLReadings[Dposition].High, 0) + "°/" + String(HLReadings[Dposition].Low, 0) + "°", CENTER);
      display.drawRect(x - 18, y - 27, fwidth, 51, GxEPD_BLACK);
    }
    //#########################################################################################
    void Draw_Main_Weather_Section() {
      DisplayConditionsSection(205, 45, WxConditions[0].Icon, LargeIcon);
      u8g2Fonts.setFont(u8g2_font_helvB14_tf);
      drawString(3, 33, String(WxConditions[0].Temperature, 1) + "° / " + String(WxConditions[0].Humidity, 0) + "%", LEFT);
      u8g2Fonts.setFont(u8g2_font_helvB10_tf);
      DrawWind(270, 37, WxConditions[0].Winddir, WxConditions[0].Windspeed);
      if (WxConditions[0].Rainfall > 0.005 || WxConditions[0].Snowfall > 0.005) {
        if (WxConditions[0].Rainfall > 0.005) drawString(170, 66, String(WxConditions[0].Rainfall, 1) + (Units == "M" ? "mm " : "in ") + TXT_PRECIPITATION_SOON, LEFT);
        else drawString(170, 66, String(WxConditions[0].Snowfall, 1) + (Units == "M" ? "mm " : "in ") + TXT_PRECIPITATION_SOON, LEFT); // Rain has precedence over snow if both reported!
      }
      DrawPressureTrend(3, 49, WxConditions[0].Pressure, WxConditions[0].Trend);
      u8g2Fonts.setFont(u8g2_font_helvB12_tf);
      String Wx_Description = WxConditions[0].Forecast0;
      drawString(2, 63, TitleCase(Wx_Description), LEFT);
      display.drawLine(0, 77, 296, 77, GxEPD_BLACK);
      DisplayAstronomySection(170, 64); // Astronomy section Sun rise/set and Moon phase plus icon
    }
    //#########################################################################################
    void DisplayAstronomySection(int x, int y) {
      display.drawRect(x, y + 13, 126, 51, GxEPD_BLACK);
      u8g2Fonts.setFont(u8g2_font_helvB08_tf);
      SunRise(x + 64, y + 23);
      drawString(x + 80, y + 20, ConvertUnixTime(WxConditions[0].Sunrise + WxConditions[0].Timezone).substring(0, (Units == "M" ? 5 : 7)), LEFT);
      SunSet(x + 64, y + 38);
      drawString(x + 80, y + 35, ConvertUnixTime(WxConditions[0].Sunset + WxConditions[0].Timezone).substring(0, (Units == "M" ? 5 : 7)), LEFT);
      time_t now = time(NULL);
      struct tm * now_utc = gmtime(&now);
      const int day_utc   = now_utc->tm_mday;
      const int month_utc = now_utc->tm_mon + 1;
      const int year_utc  = now_utc->tm_year + 1900;
      drawString(x + 6, y + 53, MoonPhase(day_utc, month_utc, year_utc, Hemisphere), LEFT);
      DrawMoon(x - 12, y - 1, day_utc, month_utc, year_utc, Hemisphere);
    }
    //#########################################################################################
    String MoonPhase(int d, int m, int y, String hemisphere) {
      int c, e;
      double jd;
      int b;
      if (m < 3) {
        y--;
        m += 12;
      }
      ++m;
      c   = 365.25 * y;
      e   = 30.6  * m;
      jd  = c + e + d - 694039.09;     /* jd is total days elapsed */
      jd /= 29.53059;                        /* divide by the moon cycle (29.53 days) */
      b   = jd;                              /* int(jd) -> b, take integer part of jd */
      jd -= b;                               /* subtract integer part to leave fractional part of original jd */
      b   = jd * 8 + 0.5;                /* scale fraction from 0-8 and round by adding 0.5 */
      b   = b & 7;                           /* 0 and 8 are the same phase so modulo 8 for 0 */
      if (hemisphere == "south") b = 7 - b;
      if (b == 0) return TXT_MOON_NEW;              // New;              0%  illuminated
      if (b == 1) return TXT_MOON_WAXING_CRESCENT;  // Waxing crescent; 25%  illuminated
      if (b == 2) return TXT_MOON_FIRST_QUARTER;    // First quarter;   50%  illuminated
      if (b == 3) return TXT_MOON_WAXING_GIBBOUS;   // Waxing gibbous;  75%  illuminated
      if (b == 4) return TXT_MOON_FULL;             // Full;            100% illuminated
      if (b == 5) return TXT_MOON_WANING_GIBBOUS;   // Waning gibbous;  75%  illuminated
      if (b == 6) return TXT_MOON_THIRD_QUARTER;    // Third quarter;   50%  illuminated
      if (b == 7) return TXT_MOON_WANING_CRESCENT;  // Waning crescent; 25%  illuminated
      return "";
    }
    //#########################################################################################
    void DrawMoon(int x, int y, int dd, int mm, int yy, String hemisphere) {
      const int diameter = 34;
      double Phase = NormalizedMoonPhase(dd, mm, yy);
      hemisphere.toLowerCase();
      if (hemisphere == "south") Phase = 1 - Phase;
      // Draw dark part of moon
      display.fillCircle(x + diameter - 1, y + diameter, diameter / 2, GxEPD_BLACK);
      const int number_of_lines = 90;
      for (double Ypos = 0; Ypos <= number_of_lines / 2; Ypos++) {
        double Xpos = sqrt(number_of_lines / 2 * number_of_lines / 2 - Ypos * Ypos);
        // Determine the edges of the lighted part of the moon
        double Rpos = 2 * Xpos;
        double Xpos1, Xpos2;
        if (Phase < 0.5) {
          Xpos1 = -Xpos;
          Xpos2 = Rpos - 2 * Phase * Rpos - Xpos;
        }
        else {
          Xpos1 = Xpos;
          Xpos2 = Xpos - 2 * Phase * Rpos + Rpos;
        }
        // Draw light part of moon
        double pW1x = (Xpos1 + number_of_lines) / number_of_lines * diameter + x;
        double pW1y = (number_of_lines - Ypos)  / number_of_lines * diameter + y;
        double pW2x = (Xpos2 + number_of_lines) / number_of_lines * diameter + x;
        double pW2y = (number_of_lines - Ypos)  / number_of_lines * diameter + y;
        double pW3x = (Xpos1 + number_of_lines) / number_of_lines * diameter + x;
        double pW3y = (Ypos + number_of_lines)  / number_of_lines * diameter + y;
        double pW4x = (Xpos2 + number_of_lines) / number_of_lines * diameter + x;
        double pW4y = (Ypos + number_of_lines)  / number_of_lines * diameter + y;
        display.drawLine(pW1x, pW1y, pW2x, pW2y, GxEPD_WHITE);
        display.drawLine(pW3x, pW3y, pW4x, pW4y, GxEPD_WHITE);
      }
      display.drawCircle(x + diameter - 1, y + diameter, diameter / 2, GxEPD_BLACK);
    }
    //#########################################################################################
    void DrawWind(int x, int y, float angle, float windspeed) {
    #define Cradius 18
      float dx = Cradius * cos((angle - 90) * PI / 180) + x; // calculate X position
      float dy = Cradius * sin((angle - 90) * PI / 180) + y; // calculate Y position
      arrow(x, y, Cradius - 10, angle, 10, 20); // Show wind direction on outer circle
      display.drawCircle(x, y, Cradius + 2, GxEPD_BLACK);
      //display.drawCircle(x, y, Cradius + 3, GxEPD_BLACK);
      for (int m = 0; m < 360; m = m + 45) {
        dx = Cradius * cos(m * PI / 180); // calculate X position
        dy = Cradius * sin(m * PI / 180); // calculate Y position
        display.drawLine(x + dx, y + dy, x + dx * 0.8, y + dy * 0.8, GxEPD_BLACK);
      }
      u8g2Fonts.setFont(u8g2_font_helvB10_tf);
      drawString(x - 10 + (WindDegToDirection(angle).length() < 2 ? 10 : 0), y + Cradius + 12, WindDegToDirection(angle), CENTER);
      u8g2Fonts.setFont(u8g2_font_helvB08_tf);
      drawString(x + 5, y - Cradius - 15, String(windspeed, 1) + (Units == "M" ? " m/s" : " mph"), CENTER);
    }
    //#########################################################################################
    String WindDegToDirection(float winddirection) {
      if (winddirection >= 348.75 || winddirection < 11.25)  return TXT_N;
      if (winddirection >=  11.25 && winddirection < 33.75)  return TXT_NNE;
      if (winddirection >=  33.75 && winddirection < 56.25)  return TXT_NE;
      if (winddirection >=  56.25 && winddirection < 78.75)  return TXT_ENE;
      if (winddirection >=  78.75 && winddirection < 101.25) return TXT_E;
      if (winddirection >= 101.25 && winddirection < 123.75) return TXT_ESE;
      if (winddirection >= 123.75 && winddirection < 146.25) return TXT_SE;
      if (winddirection >= 146.25 && winddirection < 168.75) return TXT_SSE;
      if (winddirection >= 168.75 && winddirection < 191.25) return TXT_S;
      if (winddirection >= 191.25 && winddirection < 213.75) return TXT_SSW;
      if (winddirection >= 213.75 && winddirection < 236.25) return TXT_SW;
      if (winddirection >= 236.25 && winddirection < 258.75) return TXT_WSW;
      if (winddirection >= 258.75 && winddirection < 281.25) return TXT_W;
      if (winddirection >= 281.25 && winddirection < 303.75) return TXT_WNW;
      if (winddirection >= 303.75 && winddirection < 326.25) return TXT_NW;
      if (winddirection >= 326.25 && winddirection < 348.75) return TXT_NNW;
      return "?";
    }
    //#########################################################################################
    void arrow(int x, int y, int asize, float aangle, int pwidth, int plength) {
      // x,y is the centre poistion of the arrow and asize is the radius out from the x,y position
      // aangle is angle to draw the pointer at e.g. at 45° for NW
      // pwidth is the pointer width in pixels
      // plength is the pointer length in pixels
      float dx = (asize - 10) * cos((aangle - 90) * PI / 180) + x; // calculate X position
      float dy = (asize - 10) * sin((aangle - 90) * PI / 180) + y; // calculate Y position
      float x1 = 0;         float y1 = plength;
      float x2 = pwidth / 2;  float y2 = pwidth / 2;
      float x3 = -pwidth / 2; float y3 = pwidth / 2;
      float angle = aangle * PI / 180 - 135;
      float xx1 = x1 * cos(angle) - y1 * sin(angle) + dx;
      float yy1 = y1 * cos(angle) + x1 * sin(angle) + dy;
      float xx2 = x2 * cos(angle) - y2 * sin(angle) + dx;
      float yy2 = y2 * cos(angle) + x2 * sin(angle) + dy;
      float xx3 = x3 * cos(angle) - y3 * sin(angle) + dx;
      float yy3 = y3 * cos(angle) + x3 * sin(angle) + dy;
      display.fillTriangle(xx1, yy1, xx3, yy3, xx2, yy2, GxEPD_BLACK);
    }
    //#########################################################################################
    void DrawPressureTrend(int x, int y, float pressure, String slope) {
      drawString(x, y - 3, String(pressure, (Units == "M" ? 0 : 1)) + (Units == "M" ? " hPa" : " in"), LEFT);
      x = x + 52 - (Units == "M" ? 0 : 15); y = y + 3;
      if      (slope == "+") {
        display.drawLine(x,  y, x + 4, y - 4, GxEPD_BLACK);
        display.drawLine(x + 4, y - 4, x + 8, y, GxEPD_BLACK);
      }
      else if (slope == "0") {
        display.drawLine(x + 3, y - 4, x + 8, y, GxEPD_BLACK);
        display.drawLine(x + 3, y + 4, x + 8, y, GxEPD_BLACK);
      }
      else if (slope == "-") {
        display.drawLine(x,  y, x + 4, y + 4, GxEPD_BLACK);
        display.drawLine(x + 4, y + 4, x + 8, y, GxEPD_BLACK);
      }
    }
    //#########################################################################################
    void DisplayConditionsSection(int x, int y, String IconName, bool IconSize) {
      Serial.println("Icon name: " + IconName);
      if      (IconName == "01d" || IconName == "01n")  ClearSky(x, y, IconSize, IconName);
      else if (IconName == "02d" || IconName == "02n")  FewClouds(x, y, IconSize, IconName);
      else if (IconName == "03d" || IconName == "03n")  ScatteredClouds(x, y, IconSize, IconName);
      else if (IconName == "04d" || IconName == "04n")  BrokenClouds(x, y, IconSize, IconName);
      else if (IconName == "09d" || IconName == "09n")  ChanceRain(x, y, IconSize, IconName);
      else if (IconName == "10d" || IconName == "10n")  Rain(x, y, IconSize, IconName);
      else if (IconName == "11d" || IconName == "11n")  Tstorms(x, y, IconSize, IconName);
      else if (IconName == "13d" || IconName == "13n")  Snow(x, y, IconSize, IconName);
      else if (IconName == "50d" || IconName == "50n")  Mist(x, y, IconSize, IconName);
      else                                              Nodata(x, y, IconSize, IconName);
    }
    //#########################################################################################
    void GetHighsandLows() {
      for (int d = 0; d < max_readings; d++) {
        HLReadings[d].Time = "";
        HLReadings[d].High = (Units == "M"?-50:-58);
        HLReadings[d].Low  = (Units == "M"?70:158);
      }
      int Day = 0;
      String StartTime  = "08:00" + String((Units == "M" ? "" : "a"));
      String FinishTime = "10:00" + String((Units == "M" ? "" : "a"));
      for (int r = 0; r < max_readings; r++) {
        if (ConvertUnixTime(WxForecast[r].Dt + WxConditions[0].Timezone).substring(0, (Units == "M" ? 5 : 6)) >= StartTime && ConvertUnixTime(WxForecast[r].Dt + WxForecast[r].Timezone).substring(0, (Units == "M" ? 5 : 6)) <= FinishTime) { // found first period in day
          HLReadings[Day].Time = ConvertUnixTime(WxForecast[r].Dt + WxConditions[0].Timezone).substring(0, (Units == "M" ? 5 : 6));
          for (int InDay = 0; InDay < 8; InDay++) { // 00:00 to 21:00 is 8 readings
            if (r + InDay < max_readings) {
              if (WxForecast[r + InDay].High > HLReadings[Day].High) {
                HLReadings[Day].High = WxForecast[r + InDay].High;
              }
              if (WxForecast[r + InDay].Low  < HLReadings[Day].Low)  {
                HLReadings[Day].Low  = WxForecast[r + InDay].Low;
              }
            }
          }
          //Serial.println("Cnt= " + String(Day) + "Day=" + HLReadings[Day].Time + " " + String(HLReadings[Day].High) + " " + String(HLReadings[Day].Low));
          Day++;
        }
      }
    } // Now the array HLReadings has 5-days of Highs and Lows
    //#########################################################################################
    uint8_t StartWiFi() {
      Serial.println("\r\nConnecting to: " + String(ssid));
      IPAddress dns(8, 8, 8, 8); // Use Google DNS
      WiFi.disconnect();
      WiFi.mode(WIFI_STA); // switch off AP
     
      //WiFi.setAutoConnect(true);
      WiFi.setAutoReconnect(true);
      WiFi.begin(ssid, password);
      if (WiFi.waitForConnectResult() != WL_CONNECTED) {
        Serial.printf("STA: Failed!\n");
        WiFi.disconnect(false);
        delay(500);
        WiFi.begin(ssid, password);
      }
      if (WiFi.status() == WL_CONNECTED) {
        wifi_signal = WiFi.RSSI(); // Get Wifi Signal strength now, because the WiFi will be turned off to save power!
        Serial.println("WiFi connected at: " + WiFi.localIP().toString());
      }
      else Serial.println("WiFi connection *** FAILED ***");
      return WiFi.status();
    }
    //#########################################################################################
    void StopWiFi() {
      WiFi.disconnect();
      WiFi.mode(WIFI_OFF);
    }
    //#########################################################################################
    boolean SetupTime() {
      configTime(gmtOffset_sec, daylightOffset_sec, ntpServer, "time.nist.gov"); //(gmtOffset_sec, daylightOffset_sec, ntpServer)
      setenv("TZ", Timezone, 1);  //setenv()adds the "TZ" variable to the environment with a value TimeZone, only used if set to 1, 0 means no change
      tzset(); // Set the TZ environment variable
      delay(100);
      bool TimeStatus = UpdateLocalTime();
      return TimeStatus;
    }
    //#########################################################################################
    boolean UpdateLocalTime() {
      struct tm timeinfo;
      char   time_output[30], day_output[30], update_time[30];
      while (!getLocalTime(&timeinfo, 5000)) { // Wait for 5-sec for time to synchronise
        Serial.println("Failed to obtain time");
        return false;
      }
      CurrentHour = timeinfo.tm_hour;
      CurrentMin  = timeinfo.tm_min;
      CurrentSec  = timeinfo.tm_sec;
      //See http://www.cplusplus.com/reference/ctime/strftime/
      //Serial.println(&timeinfo, "%a %b %d %Y   %H:%M:%S");      // Displays: Saturday, June 24 2017 14:05:49
      if (Units == "M") {
        if ((Language == "CZ") || (Language == "DE") || (Language == "NL") || (Language == "PL")) {
          sprintf(day_output, "%s, %02u. %s %04u", weekday_D[timeinfo.tm_wday], timeinfo.tm_mday, month_M[timeinfo.tm_mon], (timeinfo.tm_year) + 1900); // day_output >> So., 23. Juni 2019 <<
        }
        else
        {
          //sprintf(day_output, "%s  %02u-%s-%04u", weekday_D[timeinfo.tm_wday], timeinfo.tm_mday, month_M[timeinfo.tm_mon], (timeinfo.tm_year) + 1900);
          sprintf(day_output, "%s  %02u %s %04u", weekday_D[timeinfo.tm_wday], timeinfo.tm_mday, month_M[timeinfo.tm_mon], (timeinfo.tm_year) + 1900);
        }
        strftime(update_time, sizeof(update_time), "%H:%M:%S", &timeinfo);  // Creates: '@ 14:05:49'   and change from 30 to 8 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        sprintf(time_output, "%s", update_time);
      }
      else
      {
        strftime(day_output, sizeof(day_output), "%a %b-%d-%Y", &timeinfo); // Creates  'Sat May-31-2019'
        strftime(update_time, sizeof(update_time), "%r", &timeinfo);        // Creates: '02:05:49pm'
        sprintf(time_output, "%s", update_time);
      }
      date_str = day_output;
      time_str = time_output;
      return true;
    }
    //#########################################################################################
    void DrawBattery(int x, int y) {
      uint8_t percentage = 100;
      //float voltage = analogRead(0) / 4096.0 * 7.46; //<=== (35)
      //float voltage = 3.50;  
     
      float v_mes = analogRead(pinVb);
      float voltage = 1.435*(v_mes/4095)*3.3;
      Serial.println(voltage);
      delay(100);
     
     
      if (voltage > 1 ) { // Only display if there is a valid reading
        Serial.println("Voltage = " + String(voltage));
        percentage = 2836.9625 * pow(voltage, 4) - 43987.4889 * pow(voltage, 3) + 255233.8134 * pow(voltage, 2) - 656689.7123 * voltage + 632041.7303;
        if (voltage >= 4.20) percentage = 100;
        if (voltage <= 3.50) percentage = 0;
        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);
        //drawString(x + 13, y + 5,  String(voltage, 2) + "v", CENTER);
      }
    }
    //#########################################################################################
    // Symbols are drawn on a relative 10x10grid and 1 scale unit = 1 drawing unit
    void addcloud(int x, int y, int scale, int linesize) {
      //Draw cloud outer
      display.fillCircle(x - scale * 3, y, scale, GxEPD_BLACK);                // Left most circle
      display.fillCircle(x + scale * 3, y, scale, GxEPD_BLACK);                // Right most circle
      display.fillCircle(x - scale, y - scale, scale * 1.4, GxEPD_BLACK);    // left middle upper circle
      display.fillCircle(x + scale * 1.5, y - scale * 1.3, scale * 1.75, GxEPD_BLACK); // Right middle upper circle
      display.fillRect(x - scale * 3 - 1, y - scale, scale * 6, scale * 2 + 1, GxEPD_BLACK); // Upper and lower lines
      //Clear cloud inner
      display.fillCircle(x - scale * 3, y, scale - linesize, GxEPD_WHITE);            // Clear left most circle
      display.fillCircle(x + scale * 3, y, scale - linesize, GxEPD_WHITE);            // Clear right most circle
      display.fillCircle(x - scale, y - scale, scale * 1.4 - linesize, GxEPD_WHITE);  // left middle upper circle
      display.fillCircle(x + scale * 1.5, y - scale * 1.3, scale * 1.75 - linesize, GxEPD_WHITE); // Right middle upper circle
      display.fillRect(x - scale * 3 + 2, y - scale + linesize - 1, scale * 5.9, scale * 2 - linesize * 2 + 2, GxEPD_WHITE); // Upper and lower lines
    }
    //#########################################################################################
    void addraindrop(int x, int y, int scale) {
      display.fillCircle(x, y, scale / 2, GxEPD_BLACK);
      display.fillTriangle(x - scale / 2, y, x, y - scale * 1.2, x + scale / 2, y , GxEPD_BLACK);
      x = x + scale * 1.6; y = y + scale / 3;
      display.fillCircle(x, y, scale / 2, GxEPD_BLACK);
      display.fillTriangle(x - scale / 2, y, x, y - scale * 1.2, x + scale / 2, y , GxEPD_BLACK);
    }
    //#########################################################################################
    void addrain(int x, int y, int scale, bool IconSize) {
      if (IconSize == SmallIcon) scale *= 1.34;
      for (int d = 0; d < 4; d++) {
        addraindrop(x + scale * (7.8 - d * 1.95) - scale * 5.2, y + scale * 2.1 - scale / 6, scale / 1.6);
      }
    }
    //#########################################################################################
    void addsnow(int x, int y, int scale, bool IconSize) {
      int dxo, dyo, dxi, dyi;
      for (int flakes = 0; flakes < 5; flakes++) {
        for (int i = 0; i < 360; i = i + 45) {
          dxo = 0.5 * scale * cos((i - 90) * 3.14 / 180); dxi = dxo * 0.1;
          dyo = 0.5 * scale * sin((i - 90) * 3.14 / 180); dyi = dyo * 0.1;
          display.drawLine(dxo + x + flakes * 1.5 * scale - scale * 3, dyo + y + scale * 2, dxi + x + 0 + flakes * 1.5 * scale - scale * 3, dyi + y + scale * 2, GxEPD_BLACK);
        }
      }
    }
    //#########################################################################################
    void addtstorm(int x, int y, int scale) {
      y = y + scale / 2;
      for (int i = 0; i < 5; i++) {
        display.drawLine(x - scale * 4 + scale * i * 1.5 + 0, y + scale * 1.5, x - scale * 3.5 + scale * i * 1.5 + 0, y + scale, GxEPD_BLACK);
        if (scale != Small) {
          display.drawLine(x - scale * 4 + scale * i * 1.5 + 1, y + scale * 1.5, x - scale * 3.5 + scale * i * 1.5 + 1, y + scale, GxEPD_BLACK);
          display.drawLine(x - scale * 4 + scale * i * 1.5 + 2, y + scale * 1.5, x - scale * 3.5 + scale * i * 1.5 + 2, y + scale, GxEPD_BLACK);
        }
        display.drawLine(x - scale * 4 + scale * i * 1.5, y + scale * 1.5 + 0, x - scale * 3 + scale * i * 1.5 + 0, y + scale * 1.5 + 0, GxEPD_BLACK);
        if (scale != Small) {
          display.drawLine(x - scale * 4 + scale * i * 1.5, y + scale * 1.5 + 1, x - scale * 3 + scale * i * 1.5 + 0, y + scale * 1.5 + 1, GxEPD_BLACK);
          display.drawLine(x - scale * 4 + scale * i * 1.5, y + scale * 1.5 + 2, x - scale * 3 + scale * i * 1.5 + 0, y + scale * 1.5 + 2, GxEPD_BLACK);
        }
        display.drawLine(x - scale * 3.5 + scale * i * 1.4 + 0, y + scale * 2.5, x - scale * 3 + scale * i * 1.5 + 0, y + scale * 1.5, GxEPD_BLACK);
        if (scale != Small) {
          display.drawLine(x - scale * 3.5 + scale * i * 1.4 + 1, y + scale * 2.5, x - scale * 3 + scale * i * 1.5 + 1, y + scale * 1.5, GxEPD_BLACK);
          display.drawLine(x - scale * 3.5 + scale * i * 1.4 + 2, y + scale * 2.5, x - scale * 3 + scale * i * 1.5 + 2, y + scale * 1.5, GxEPD_BLACK);
        }
      }
    }
    //#########################################################################################
    void addsun(int x, int y, int scale, bool IconSize) {
      int linesize = 3;
      if (IconSize == SmallIcon) linesize = 1;
      display.fillRect(x - scale * 2, y, scale * 4, linesize, GxEPD_BLACK);
      display.fillRect(x, y - scale * 2, linesize, scale * 4, GxEPD_BLACK);
      display.drawLine(x - scale * 1.3, y - scale * 1.3, x + scale * 1.3, y + scale * 1.3, GxEPD_BLACK);
      display.drawLine(x - scale * 1.3, y + scale * 1.3, x + scale * 1.3, y - scale * 1.3, GxEPD_BLACK);
      if (IconSize == LargeIcon) {
        display.drawLine(1 + x - scale * 1.3, y - scale * 1.3, 1 + x + scale * 1.3, y + scale * 1.3, GxEPD_BLACK);
        display.drawLine(2 + x - scale * 1.3, y - scale * 1.3, 2 + x + scale * 1.3, y + scale * 1.3, GxEPD_BLACK);
        display.drawLine(3 + x - scale * 1.3, y - scale * 1.3, 3 + x + scale * 1.3, y + scale * 1.3, GxEPD_BLACK);
        display.drawLine(1 + x - scale * 1.3, y + scale * 1.3, 1 + x + scale * 1.3, y - scale * 1.3, GxEPD_BLACK);
        display.drawLine(2 + x - scale * 1.3, y + scale * 1.3, 2 + x + scale * 1.3, y - scale * 1.3, GxEPD_BLACK);
        display.drawLine(3 + x - scale * 1.3, y + scale * 1.3, 3 + x + scale * 1.3, y - scale * 1.3, GxEPD_BLACK);
      }
      display.fillCircle(x, y, scale * 1.3, GxEPD_WHITE);
      display.fillCircle(x, y, scale, GxEPD_BLACK);
      display.fillCircle(x, y, scale - linesize, GxEPD_WHITE);
    }
    //#########################################################################################
    void addfog(int x, int y, int scale, int linesize, bool IconSize) {
      if (IconSize == SmallIcon) {
        linesize = 1;
        y = y - 1;
      } else y = y - 3;
      for (int i = 0; i < 6; i++) {
        display.fillRect(x - scale * 3, y + scale * 1.5, scale * 6, linesize, GxEPD_BLACK);
        display.fillRect(x - scale * 3, y + scale * 2.0, scale * 6, linesize, GxEPD_BLACK);
        display.fillRect(x - scale * 3, y + scale * 2.6, scale * 6, linesize, GxEPD_BLACK);
      }
    }
    //#########################################################################################
    void ClearSky(int x, int y, bool IconSize, String IconName) {
      int scale = Small;
      if (IconSize == LargeIcon) {
        scale = Large;
        y = y - 6; // Shift up large sun
      }
      else {
        y = y - 5; // Shift down small sun icon
      }
      if (IconName.endsWith("n")) addmoon(x, y + 3, scale, IconSize);
      scale = scale * 1.6;
      addsun(x, y, scale, IconSize);
    }
    //#########################################################################################
    void FewClouds(int x, int y, bool IconSize, String IconName) {
      int scale = Small, linesize = 1;
      if (IconSize == LargeIcon) {
        scale = Large;
        linesize = 3;
      }
      if (IconName.endsWith("n")) addmoon(x, y, scale, IconSize);
      addsun(x - scale * 1.8, y - scale * 1.8, scale, IconSize);
      addcloud(x, y, scale, linesize);
    }//#########################################################################################
    void ScatteredClouds(int x, int y, bool IconSize, String IconName) {
      int scale = Small, linesize = 3, offset = 10;
      if (IconSize == LargeIcon) {
        scale = Large;
      }
      else
      {
        linesize = 1;
        offset   = 5;
      }
      if (IconName.endsWith("n")) addmoon(x, y + offset + (IconSize ? -8 : 0), scale, IconSize);
      addcloud(x + offset, y - offset * 1.2, scale / 1.5, linesize);
      addcloud(x, y + offset, scale, linesize);
      addsun(x - scale * 1.8, y - scale * 1.8 + offset, scale, IconSize);
    }
    //#########################################################################################
    void BrokenClouds(int x, int y, bool IconSize, String IconName) {
      int scale = Small, linesize = 3, offset  = 12;
      if (IconSize == LargeIcon) {
        scale = Large;
      }
      else
      {
        linesize = 1;
        offset   = 6;
      }
      if (IconName.endsWith("n")) addmoon(x, y, scale, IconSize);
      addcloud(x - offset, y - offset, scale / 1.5, linesize);
      addcloud(x + offset, y - offset * 1.2, scale / 1.5, linesize);
      addcloud(x, y, scale, linesize);
    }
    //#########################################################################################
    void Rain(int x, int y, bool IconSize, String IconName) {
      int scale = Large, linesize = 3;
      if (IconSize == SmallIcon) {
        scale = Small;
        linesize = 1;
      }
      if (IconName.endsWith("n")) addmoon(x, y, scale, IconSize);
      addcloud(x, y, scale, linesize);
      addrain(x, y, scale, IconSize);
    }
    //#########################################################################################
    void ChanceRain(int x, int y, bool IconSize, String IconName) {
      int scale = Large, linesize = 3;
      if (IconSize == SmallIcon) {
        scale = Small;
        linesize = 1;
      }
      if (IconName.endsWith("n")) addmoon(x - (IconSize ? 8 : 0), y, scale, IconSize);
      addsun(x - scale * 1.8, y - scale * 1.8, scale, IconSize);
      addcloud(x, y, scale, linesize);
      addrain(x, y, scale, IconSize);
    }
    //#########################################################################################
    void ExpectRain(int x, int y, bool IconSize, String IconName) {
      int scale = Large, linesize = 3;
      if (IconSize == SmallIcon) {
        scale = Small;
        linesize = 1;
      }
      if (IconName.endsWith("n")) addmoon(x, y, scale, IconSize);
      addsun(x - scale * 1.8, y - scale * 1.8, scale, IconSize);
      addcloud(x, y, scale, linesize);
      addrain(x, y, scale, IconSize);
    }
    //#########################################################################################
    void Tstorms(int x, int y, bool IconSize, String IconName) {
      int scale = Large, linesize = 3;
      if (IconSize == SmallIcon) {
        scale = Small;
        linesize = 1;
      }
      if (IconName.endsWith("n")) addmoon(x, y, scale, IconSize);
      addcloud(x, y, scale, linesize);
      addtstorm(x, y, scale);
    }
    //#########################################################################################
    void Snow(int x, int y, bool IconSize, String IconName) {
      int scale = Large, linesize = 3;
      if (IconSize == SmallIcon) {
        scale = Small;
        linesize = 1;
      }
      if (IconName.endsWith("n")) addmoon(x, y, scale, IconSize);
      addcloud(x, y, scale, linesize);
      addsnow(x, y, scale, IconSize);
    }
    //#########################################################################################
    void Mist(int x, int y, bool IconSize, String IconName) {
      int linesize = 3, scale = Large;
      if (IconSize == SmallIcon) {
        scale = Small;
        linesize = 1;
        y = y + 5;
      }
      if (IconName.endsWith("n")) addmoon(x, y, scale, IconSize);
      addcloud(x, y - 5, scale, linesize);
      addfog(x, y - 2, scale, linesize, IconSize);
    }
    //#########################################################################################
    void Haze(int x, int y, bool IconSize, String IconName) {
      int linesize = 3, scale = Large;
      if (IconSize == SmallIcon) {
        scale = Small;
        linesize = 1;
      }
      if (IconName.endsWith("n")) addmoon(x, y, scale, IconSize);
      addsun(x, y - 2, scale * 1.4, IconSize);
      addfog(x, y + 3 - (IconSize ? 12 : 0), scale * 1.4, linesize, IconSize);
    }
    //#########################################################################################
    void CloudCover(int x, int y, int CCover) {
      addcloud(x - 9, y - 3, Small * 0.6, 2); // Cloud top left
      addcloud(x + 3, y - 3, Small * 0.6, 2); // Cloud top right
      addcloud(x, y,         Small * 0.6, 2); // Main cloud
      u8g2Fonts.setFont(u8g2_font_helvB08_tf);
      drawString(x + 15, y - 5, String(CCover) + "%", LEFT);
    }
    //#########################################################################################
    void Visibility(int x, int y, String Visi) {
      y = y - 3; //
      float start_angle = 0.52, end_angle = 2.61;
      int r = 10;
      for (float i = start_angle; i < end_angle; i = i + 0.05) {
        display.drawPixel(x + r * cos(i), y - r / 2 + r * sin(i), GxEPD_BLACK);
        display.drawPixel(x + r * cos(i), 1 + y - r / 2 + r * sin(i), GxEPD_BLACK);
      }
      start_angle = 3.61; end_angle = 5.78;
      for (float i = start_angle; i < end_angle; i = i + 0.05) {
        display.drawPixel(x + r * cos(i), y + r / 2 + r * sin(i), GxEPD_BLACK);
        display.drawPixel(x + r * cos(i), 1 + y + r / 2 + r * sin(i), GxEPD_BLACK);
      }
      display.fillCircle(x, y, r / 4, GxEPD_BLACK);
      u8g2Fonts.setFont(u8g2_font_helvB08_tf);
      drawString(x + 12, y - 3, Visi, LEFT);
    }
    //#########################################################################################
    void addmoon(int x, int y, int scale, bool IconSize) {
      if (IconSize == LargeIcon) {
        x = x - 5; y = y + 5;
        display.fillCircle(x - 21, y - 23, scale, GxEPD_BLACK);
        display.fillCircle(x - 14, y - 23, scale * 1.7, GxEPD_WHITE);
      }
      else
      {
        display.fillCircle(x - 16, y - 11, scale, GxEPD_BLACK);
        display.fillCircle(x - 11, y - 11, scale * 1.7, GxEPD_WHITE);
      }
    }
    //#########################################################################################
    void Nodata(int x, int y, bool IconSize, String IconName) {
      if (IconSize == LargeIcon) u8g2Fonts.setFont(u8g2_font_helvB24_tf); else u8g2Fonts.setFont(u8g2_font_helvB10_tf);
      drawString(x - 3, y - 8, "?", CENTER);
      u8g2Fonts.setFont(u8g2_font_helvB08_tf);
    }
    //#########################################################################################
    void SunRise(int x, int y) {
      u8g2Fonts.setFont(u8g2_font_helvB08_tf);
      addsun(x, y, 3, SmallIcon);
      display.drawFastVLine(x + 10, y - 6, 10, GxEPD_BLACK);
      display.drawLine(x + 10 - 3, y - 6 + 3, x + 10, y - 6, GxEPD_BLACK);
      display.drawLine(x + 10 + 3, y - 6 + 3, x + 10, y - 6, GxEPD_BLACK);
    }
    //#########################################################################################
    void SunSet(int x, int y) {
      u8g2Fonts.setFont(u8g2_font_helvB08_tf);
      addsun(x, y, 3, SmallIcon);
      display.drawFastVLine(x + 10, y - 6, 10, GxEPD_BLACK);
      display.drawLine(x + 10 - 3, y + 4 - 3, x + 10, y + 4, GxEPD_BLACK);
      display.drawLine(x + 10 + 3, y + 4 - 3, x + 10, y + 4, GxEPD_BLACK);
    }
    //#########################################################################################
    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;
      u8g2Fonts.setCursor(x, y + h);
      u8g2Fonts.print(text);
    }
    //#########################################################################################
    void drawStringMaxWidth(int x, int y, unsigned int text_width, 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.getTextBounds(text, x, y, &x1, &y1, &w, &h);
      if (alignment == RIGHT)  x = x - w;
      if (alignment == CENTER) x = x - w / 2;
      u8g2Fonts.setCursor(x, y);
      if (text.length() > text_width * 2) {
        u8g2Fonts.setFont(u8g2_font_helvB10_tf);
        text_width = 42;
        y = y - 3;
      }
      u8g2Fonts.println(text.substring(0, text_width));
      if (text.length() > text_width) {
        u8g2Fonts.setCursor(x, y + h + 15);
        String secondLine = text.substring(text_width);
        secondLine.trim(); // Remove any leading spaces
        u8g2Fonts.println(secondLine);
      }
    }
    //#########################################################################################
    String GetForecastDay(int unix_time) {
      // Returns either '21:12  ' or ' 09:12pm' depending on Units mode
      time_t tm = unix_time;
      struct tm *now_tm = localtime(&tm);
      char output[40], FDay[40];
      if (Units == "M") {
        strftime(output, sizeof(output), "%H:%M %d/%m/%y", now_tm);
        strftime(FDay, sizeof(FDay), "%w", now_tm);
      }
      else {
        strftime(output, sizeof(output), "%I:%M%p %m/%d/%y", now_tm);
        strftime(FDay, sizeof(FDay), "%w", now_tm);
      }
      ForecastDay = weekday_D[String(FDay).toInt()];
      return output;
    }
    //#########################################################################################
    void InitialiseDisplay() {
      //display.init(115200, true, 2, false);
      display.init(115200); //for older Waveshare HAT's
      //SPI.end();
      //SPI.begin(EPD_SCK, EPD_MISO, EPD_MOSI, EPD_CS);
      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();
    }
     
    /*
      Version 6.0 reformatted to use u8g2 fonts
      1.  Screen layout revised
      2.  Made consitent with other versions specifically 7x5 variant
      3.  Introduced Visibility in Metres, Cloud cover in % and RH in %
      4.  Correct sunrise/sunset time when in imperial mode.
     
      Version 6.1 Provided connection support for Waveshare ESP32 driver board
     
      Version 6.2 Changed GxEPD2 initialisation from 115200 to 0
      1.  display.init(115200); becomes display.init(0); to stop blank screen following update to GxEPD2
     
      Version 6.3 changed u8g2 fonts selection
       1.  Omitted 'FONT(' and added _tf to font names either Regular (R) or Bold (B)
     
      Version 6.4
       1. Added an extra 20-secs sleep delay to allow for slow ESP32 RTC timers
     
      Version 6.5
      1. Modified for GxEPD2
     
      Version 7.0
      1. Added 3-dayy forecasting
     
    */
    mais si j'utilise les mêmes branchements de la carte Epaper avec le même ESP32 mais avec cet autre programme de test , çà ne fonctionne pas tout en passant par la fonction <<InitialiseDisplay();>>
    je ne comprends pas pourquoi

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #include <SPI.h>
    #include "RTClib.h"
    #include "driver/rtc_io.h"
    //#include <ArduinoJson.h>
    #include <Wire.h>
    #include <time.h>
    #include <common.h>
     
    #define  ENABLE_GxEPD2_display 0
    #include <GxEPD2_BW.h>
    #include <U8g2_for_Adafruit_GFX.h>
     
    //#define ENABLE_GxEPD2_display 0
    #define SCREEN_WIDTH   296
    #define SCREEN_HEIGHT  128
     
    GxEPD2_BW<GxEPD2_290_T94, GxEPD2_290_T94::HEIGHT> display(GxEPD2_290_T94(/*CS=5*/ 27, /*DC=*/ 14, /*RST=*/ 12, /*BUSY=*/ 13)); // GDEM029T94 128x296, SSD1680
    U8G2_FOR_ADAFRUIT_GFX u8g2Fonts; 
     
    // LED pour l'indication visuelle
    const int ledPin = 32;
     
    void setup() {
      //Serial.begin(115200);
      pinMode (ledPin, OUTPUT);
      digitalWrite(ledPin, HIGH);
      delay(1000);
      digitalWrite(ledPin, LOW);
      InitialiseDisplay();
    }
     
    void loop() {
      // put your main code here, to run repeatedly:
     
    }
     
    //#########################################################################################
    void InitialiseDisplay() {
      //display.init(115200, true, 2, false);
      display.init(9600); //for older Waveshare HAT's
      //SPI.end();
      //SPI.begin(EPD_SCL, EPD_SDA);
      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();
     
    }
    si une âme charitable pouvez svp m'expliquer ....
    pascal

  2. #2
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    Je ne comprends pas bien, ce sont deux types d’afficheurs différents non? Ils n’ont pas des exemples de code / branchements?

  3. #3
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    988
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 988
    Par défaut
    Salut Jay M

    J'utilise l'afficheur E-paper branché sur un micro ESP32 ( ici un uPesy ESP32 Wroom Low Power DevKit )

    Dans le 1er cas ; je fais fonctionner un programme de démo "constructeur" pour m'assurer que le branchement est correct
    ici : CS(SS)=27,SCL=18,SDA=23,BUSY=13,RES=12,DC=14
    et tout fonctionne normalement

    Puis je renouvelle l'expérience avec mon programme de test sans rien changer aux branchements
    je change juste le soft et là l'afficheur refuse de s'initialiser

    j'ai renouvelé plusieurs fois l'essai et le résultat est identique
    avec ce programme qui comporte les mêmes bibliothèques que celui de la démo, je n'arrive pas à faire fonctionner l’écran
    étrange

  4. #4
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    je ne connais pas cet écran mais dans le premier code je vois
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      display.init(115200, true, 2, false);
    dans le second code je vois

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      display.init(9600); //for older Waveshare HAT's

    ça parait louche non ?

  5. #5
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    988
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 988
    Par défaut
    Citation Envoyé par Jay M Voir le message
    je ne connais pas cet écran mais dans le premier code je vois
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      display.init(115200, true, 2, false);
    dans le second code je vois

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      display.init(9600); //for older Waveshare HAT's

    ça parait louche non ?
    En fait j'avais fait l'essai avec une vitesse moins élevée mais sans succès

    Ce qui par contre surprenant c'est dans le programme de démo ils utilisent dans le SETUP() :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
     
     StartTime = millis();
     //Serial.begin(115200);
     display.init(115200, true, 2, false);

    puis dans la fonction : InitialiseDisplay()

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     //display.init(115200, true, 2, false);
      display.init(115200); //for older Waveshare HAT's
    par ailleurs à quoi sert exactement ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    #include <common.h>

  6. #6
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    988
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 988
    Par défaut
    Je pense avoir trouver mon petit problème
    la diable se cache dans les détails et le détail c'est :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    display.display(false); // Full screen update mode
    par contre il n'affiche pas ce que j'attends ( cf post précédent ) j'utilise ceci pour afficher la date de lever du soleil "alarm1Date"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    void checkAlarms()
    {
        DateTime alarm1Time = rtc.getAlarm1();
        Ds3231Alarm1Mode alarm1mode = rtc.getAlarm1Mode();
        char alarm1Date[12] = "DD hh:mm:ss";
        alarm1Time.toString(alarm1Date);
        Serial.print("[ Alarme 1: ");
        Serial.print(alarm1Date);
        Serial.print(", Mode: ");
        switch (alarm1mode) {
          case DS3231_A1_PerSecond: Serial.println("PerSecond ]"); break;
          case DS3231_A1_Second: Serial.println("Second ]"); break;
          case DS3231_A1_Minute: Serial.println("Minute ]"); break;
          case DS3231_A1_Hour: Serial.println("Hour ]"); break;
          case DS3231_A1_Date: Serial.println("Date ]"); break;
          case DS3231_A1_Day: Serial.println("Day ]"); break;
        }
        Serial.print("");
     
    }
    mais l'affichage E-paper utilise ces 2 fonctions :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    
    void DisplayAstronomySection(int x, int y) {
      display.drawRect(x, y + 13, 126, 51, GxEPD_BLACK);
      u8g2Fonts.setFont(u8g2_font_helvB08_tf);
      drawString(x + 80, y + 35, alarm1Date, CENTER);
        
    }
    
    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;
      u8g2Fonts.setCursor(x, y + h);
      u8g2Fonts.print(text);
    }
    mais çà n'affiche rien , un problème d'incompatibilité je suppose ?

  7. #7
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    dans cette fonction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     void DisplayAstronomySection(int x, int y) {
      display.drawRect(x, y + 13, 126, 51, GxEPD_BLACK);
      u8g2Fonts.setFont(u8g2_font_helvB08_tf);
      drawString(x + 80, y + 35, alarm1Date, CENTER);  
    }
    d'où vient alarm1Date?

    si c'est une variable globale, elle n'a pas été modifiée quand vous avez fait
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
        char alarm1Date[12] = "DD hh:mm:ss";
        alarm1Time.toString(alarm1Date);
        Serial.print("[ Alarme 1: ");
        Serial.print(alarm1Date);
    puisque vous avez déclaré une variable locale à la fonction checkAlarms().

    Encore un problème de portée des variables?

  8. #8
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    988
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 988
    Par défaut
    Encore un problème de portée des variables?
    Je ne pense pas
    j'ai pris soin de déclarer au départ :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    char alarm1Date[12] = "";
    pour avoir au final une information comme => 11 18:51:31 avec la fonction checkAlarms()
    et c'est cette information que je souhaite afficher à l'écran sauf qu'il s'agit d'un tableau je suppose donc que je dois le modifier pour passer via la fonction DisplayAstronomySection(int x, int y)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
     
    void DisplayAstronomySection(int x, int y) {
      display.drawRect(x, y + 13, 126, 51, GxEPD_BLACK);
      u8g2Fonts.setFont(u8g2_font_helvB08_tf);
      drawString(x + 80, y + 35, alarm1Date, CENTER);
     
    }
     
    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;
      u8g2Fonts.setCursor(x, y + h);
      u8g2Fonts.print(text);
    }

  9. #9
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    988
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 988
    Par défaut
    Je dois me rendre à l'évidence :

    Comment fait-on pour mettre une variable appelée : char alarme1Date[12]
    dans une autre variable String appelée "affichalarme" qui a cette forme : "texte"+alarm1Date+"texte"+alarm1Mode

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    void checkAlarms()
    {
        DateTime alarm1Time = rtc.getAlarm1();
        Ds3231Alarm1Mode alarm1mode = rtc.getAlarm1Mode();
        char alarm1Date[12] = "DD hh:mm:ss";
        alarm1Time.toString(alarm1Date);
        Serial.print("[ Alarme 1: ");
        Serial.print(alarm1Date);
        Serial.print(", Mode: ");
        switch (alarm1mode) {
          case DS3231_A1_PerSecond: Serial.println("PerSecond ]"); break;
          case DS3231_A1_Second: Serial.println("Second ]"); break;
          case DS3231_A1_Minute: Serial.println("Minute ]"); break;
          case DS3231_A1_Hour: Serial.println("Hour ]"); break;
          case DS3231_A1_Date: Serial.println("Date ]"); break;
          case DS3231_A1_Day: Serial.println("Day ]"); break;
        }
        affichalarme[] =("[ Alarme 1: ",alarm1Date," Mode: ",alarm1mode," ]");
        Serial.print("");
     
    }

    EDIT : j'ai tenté ceci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    String affichalarme = String(affichalarme);  // <== decalration en global de la variable 
     
    ...
     
     
    void checkAlarms()
    {
        DateTime alarm1Time = rtc.getAlarm1();
        Ds3231Alarm1Mode alarm1mode = rtc.getAlarm1Mode();
        char alarm1Date[12] = "DD hh:mm:ss";
        alarm1Time.toString(alarm1Date);
        Serial.print("[ Alarme 1: ");
        Serial.print(alarm1Date);
        Serial.print(", Mode: ");
        switch (alarm1mode) {
          case DS3231_A1_PerSecond: Serial.println("PerSecond ]"); break;
          case DS3231_A1_Second: Serial.println("Second ]"); break;
          case DS3231_A1_Minute: Serial.println("Minute ]"); break;
          case DS3231_A1_Hour: Serial.println("Hour ]"); break;
          case DS3231_A1_Date: Serial.println("Date ]"); break;
          case DS3231_A1_Day: Serial.println("Day ]"); break;
        }
        affichalarme = alarm1Date;  // <==== 
        Serial.print("");
    }

  10. #10
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    essayez

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    void setup() {
      Serial.begin(115200);
     
      // disons qu'on ait 
      char alarm1Date[12] = "13 14:18:55";
      int alarm1mode = 3;
     
      // vous instanciez une String
      String affichalarme;
     
      // vous remplissez. l'approche avec += est préférable à tout mettre sur une ligne 
      // car sinon il faut créer des String intermédiaires
      affichalarme = "[ Alarme 1: ";
      affichalarme += alarm1Date;
      affichalarme += " Mode: ";
      affichalarme += alarm1mode;
      affichalarme +=  " ]";
     
      // on affiche le résultat de la concaténation
      Serial.println(affichalarme);
    }
     
    void loop() {}

  11. #11
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    988
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 988
    Par défaut
    j'ai fait ceci en declarant global une variable affichmode

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    String affichmode = String(affichmode);
    .....
     
    void checkAlarms()
    {
        DateTime alarm1Time = rtc.getAlarm1();
        Ds3231Alarm1Mode alarm1mode = rtc.getAlarm1Mode();
        //char alarm1Date[12] = "DD hh:mm:ss";
        alarm1Time.toString(alarm1Date);
        Serial.print("[ Alarme 1: ");
        Serial.print(alarm1Date);
        Serial.print(", Mode: ");
        switch (alarm1mode) {
          case DS3231_A1_PerSecond:
            Serial.println("PerSecond ]");
            affichmode = "Par Seconde";
            break;
          case DS3231_A1_Second:
            Serial.println("Second ]");
            affichmode = "Seconde";
            break;
          case DS3231_A1_Minute:
            Serial.println("Minute ]");
            affichmode = "Minute";
            break;
          case DS3231_A1_Hour:
            Serial.println("Hour ]");
             affichmode = "Heure";
            break;
          case DS3231_A1_Date:
            Serial.println("Date ]");
             affichmode = "Date";
            break;
          case DS3231_A1_Day:
            Serial.println("Day ]");
             affichmode = "Jour";
            break;
        }
        //affichalarme = alarm1Date;
        affichalarme = "[ Alarme 1: ";
        affichalarme += alarm1Date;
        affichalarme += " Mode: ";
        affichalarme += affichmode;  // <=================
        affichalarme +=  " ]";
        Serial.print("");
    }
    et une petite photo pour illustrer le résultat

    merci encore pour ta patience
    je pense clôturer le post puisque ma dernière était Hors Sujet

    Bien Cordialement
    pascal
    Images attachées Images attachées  

  12. #12
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    Je ne comprends pas ce que vous espérez de

    String affichmode = String(affichmode);


    En C++ cette expression crée un nouvel objet String en utilisant la valeur actuelle de affichmode comme argument du constructeur, puis l’affecte à une nouvelle variable affichmode locale qui masque la variable existante du même nom dans cette portée. Cela revient donc à faire une copie, mais en redéclarant une variable distincte qui cache l’ancienne.

    Ça n’a aucun sens… comprenez vous bien la notion de portée des variables ??

    (mais sinon, oui affecter la String dans the switch/case et l'utiliser ensuite c'est bien)

  13. #13
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    988
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 988
    Par défaut
    Je ne comprends pas ce que vous espérez de
    String affichmode = String(affichmode);
    Vous avez raison, çà démontre une redondance inutile mais je l'avais trouvée en ex quelque part, mais je ne comprenais pas son utilité mais comme le compilateur le prenait donc ...
    devrait suffire je pense ....

    Ça n’a aucun sens… comprenez vous bien la notion de portée des variables ??
    Non et c'est évident je n'arrive pas à telle preuve que dans le poste précédent en #17 , vous m'aviez montré on fait de la compilation séparée et de l'édition de lien (ce que l'IDE sait gérer)
    j'ai voulu en se basant sur l'exemple reproduire la même configuration pour l'affichage en faisant : affichage.h et affichage.cpp cela n'a pas fonctionné le compilateur plantait
    les variables n'étaient pas correctement déclarées , j'ai donc du renoncer car je n'arrive pas à comprendre la technique

  14. #14
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    Citation Envoyé par cobra38 Voir le message
    les variables n'étaient pas correctement déclarées , j'ai donc du renoncer car je n'arrive pas à comprendre la technique
    En C++, il faut distinguer déclaration et définition d’une variable.

    Une déclaration informe le compilateur qu’une variable existera quelque part au moment de l’édition de liens, mais elle n’alloue pas de mémoire.

    Une définition, au contraire, réserve effectivement l’espace mémoire pour cette variable.

    On peut déclarer la même variable autant de fois qu’on veut dans différents fichiers sans problème avec le mot clef extern pour dire au compilateur "voilà le type de la variable, elle existe quelque part, ne t'en fais pas tu la retrouveras plus tard" , mais il ne faut la définir qu’une seule fois dans tout le programme, sinon on obtient une erreur de type définition multiple lors de l’édition de liens.

    au lieu de déclarer chaque variable (ou fonction) en externe dans tous les fichiers, souvent on met ces déclarations dans un .h et partout où on a besoin de la connaissance de cette/ces éléments, on inclue le .h avec #include qui ne fait que recopier textuellement ce qui a dans le .h à cet endroit.


    Exemple avec un header et un fichier source :

    fichier variables.h

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    #ifndef VARIABLES_H
    #define VARIABLES_H
    extern int compteur; // on dit qu'il existera quelque part une définition d'un entier appelé compteur
    #endif

    fichier variables.cpp

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    #include "variables.h"
    int compteur = 0;
    Dans ce cas, extern int compteur; est une déclaration, visible par tous les fichiers qui incluent `variables.h`. La ligne `int globalCounter = 0;` dans `variables.cpp` est la définition unique qui alloue la mémoire. Si un autre fichier cpp écrit aussi `int globalCounter = 0;`, on aurait une erreur au à l'édition de lien.


    Le fichier .cpp est compilé indépendamment et produit un module objet (.o). Dans ce module se trouve la définition de la variable, c’est-à-dire l’instruction d’allouer de la mémoire pour elle. Comme chaque fichier .cpp n’est compilé qu’une seule fois, la définition n’existe qu’une seule fois dans ce module. C’est seulement au moment de l’édition de liens que le linker rassemble tous les modules objets pour former l’exécutable, et c’est à ce moment qu’il associe les déclarations externes vues dans d’autres fichiers avec cette définition unique. C’est pourquoi on peut écrire des déclarations partout, mais la définition doit être unique dans l’ensemble du programme.

  15. #15
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    988
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 988
    Par défaut
    merci Jay M

    pourquoi a-t-on besoin de répéter dans "variables.cpp"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    #include "variables.h"
    int compteur = 0;   <== on pourrait mettre compteur = 0; ? puisque la définition est déjà dans variables.h je me trompe ?

  16. #16
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    Citation Envoyé par cobra38 Voir le message
    merci Jay M

    pourquoi a-t-on besoin de répéter dans "variables.cpp"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    #include "variables.h"
    int compteur = 0;   <== on pourrait mettre compteur = 0; ? puisque la définition est déjà dans variables.h je me trompe ?
    Non la DECLARATION est dans variables.h. on ne fait jamais de DEFINITION dans un .h car si vous l'importez plusieurs fois, vous vous trouvez alors avec plusieurs définition (allocation de mémoire) pour la même variable.

    Pour la DEFINITION de la variable, il faut répéter le type et comme c'est une définition, la mémoire est allouée et on peut donc donner la valeur initiale qui sera stockée par le compilateur aussi dans cette mémoire.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Servlet] Fichiers d'initialisation
    Par david71 dans le forum Servlets/JSP
    Réponses: 7
    Dernier message: 03/09/2003, 13h47
  2. Créer et initialiser un composant TStatusBar :help:
    Par James_ dans le forum C++Builder
    Réponses: 10
    Dernier message: 21/08/2003, 08h52
  3. [servlet] initialisation d'objets
    Par tiPouick dans le forum Servlets/JSP
    Réponses: 11
    Dernier message: 05/08/2003, 12h12
  4. Initialisation de XMLModule
    Par Sylvain Leray dans le forum XMLRAD
    Réponses: 10
    Dernier message: 01/04/2003, 10h08
  5. initialisation Directinput avec delphi
    Par Madmaxx dans le forum DirectX
    Réponses: 1
    Dernier message: 21/02/2003, 17h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo