From aaa3086c56ab649195079bf8c45943b291070cda Mon Sep 17 00:00:00 2001 From: Laurent Claude Date: Sat, 2 Sep 2023 23:58:11 +0200 Subject: [PATCH] Changement librairie oled : Adafruit --- platformio.ini | 4 +- src/main.cpp | 129 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 95 insertions(+), 38 deletions(-) diff --git a/platformio.ini b/platformio.ini index 32fc407..a29e5c0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,5 +13,5 @@ platform = espressif32 board = esp32cam framework = arduino lib_deps = - poma/OLED_I2C @ ^2.12 - + adafruit/Adafruit SSD1306@^2.5.7 + adafruit/Adafruit GFX Library@^1.11.7 diff --git a/src/main.cpp b/src/main.cpp index 1fd63f4..ea7d691 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,55 +1,112 @@ -#include -//#include -#include + +#include +#include +#include +#include + +#define SCREEN_WIDTH 128 // OLED display width, in pixels +#define SCREEN_HEIGHT 64 // OLED display height, in pixels + +// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) +// The pins for I2C are defined by the Wire-library. +// On an arduino UNO: A4(SDA), A5(SCL) +// On an arduino MEGA 2560: 20(SDA), 21(SCL) +// On an arduino LEONARDO: 2(SDA), 3(SCL), ... +#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) +#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define SDA 12 #define SCL 13 -OLED myOLED(SDA, SCL); -extern uint8_t BigNumbers[]; -extern uint8_t SmallFont[]; - -#define SORTIE_ALIM 4 +#define SORTIE_RELAIS 2 #define LED_FLASH 4 #define LED_BUILTIN 33 -#define MyLED LED_FLASH - -int count = 7; -bool sortieAlim = false; -void setup() { - pinMode(SORTIE_ALIM, OUTPUT); - digitalWrite(SORTIE_ALIM, LOW); +// durée par défaut en secondes +int count = 12; - myOLED.begin(SSD1306_128X32); - myOLED.setFont(SmallFont); - myOLED.clrScr(); - myOLED.print("Hello", CENTER, 0); - myOLED.update(); - delay(1000); +#define LOGO_HEIGHT 32 +#define LOGO_WIDTH 32 +const unsigned char bitmap_K [] PROGMEM = { +//uint8_t bitmap_K [] PROGMEM = { + // 'K, 32x32px + 0xff, 0xff, 0xf8, 0x03, 0x80, 0x7f, 0xf0, 0x07, 0x80, 0x7f, 0xe0, 0x0f, 0x80, 0x7f, 0xc0, 0x1f, + 0x80, 0x7f, 0x80, 0x3f, 0x80, 0x7f, 0x00, 0x7f, 0x80, 0x7e, 0x00, 0xff, 0x80, 0x7c, 0x01, 0xff, + 0x80, 0xf8, 0x03, 0xff, 0x00, 0xf0, 0x07, 0xff, 0x80, 0xe0, 0x0f, 0xff, 0x80, 0xc0, 0x1f, 0xff, + 0x80, 0x00, 0x3f, 0xff, 0x00, 0x00, 0x3f, 0xff, 0x00, 0x00, 0x1f, 0xff, 0x00, 0x00, 0x0f, 0xff, + 0x00, 0x00, 0x0f, 0xff, 0x00, 0x00, 0x07, 0xff, 0x00, 0x00, 0x03, 0xff, 0x00, 0x38, 0x01, 0xff, + 0x00, 0x7c, 0x01, 0xff, 0x00, 0xfe, 0x00, 0xff, 0x00, 0xff, 0x00, 0x7f, 0x00, 0xff, 0x00, 0x3f, + 0x00, 0xff, 0x80, 0x3f, 0x00, 0xff, 0xc0, 0x1f, 0x00, 0xff, 0xe0, 0x0f, 0x00, 0xff, 0xe0, 0x07, + 0x00, 0xff, 0xf0, 0x07, 0x00, 0xff, 0xf8, 0x03, 0x00, 0xff, 0xf8, 0x01, 0x00, 0xff, 0xfc, 0x01 +}; + +void testdrawchar(void) { + display.clearDisplay(); + + display.setTextSize(5); // Normal 1:1 pixel scale + display.setTextColor(SSD1306_WHITE); // Draw white text + display.setCursor(0, 0); // Start at top-left corner + display.cp437(true); // Use full 256 char 'Code Page 437' font + + // Not all the characters will fit on the display. This is normal. + // Library will draw what it can and the rest will be clipped. + for(int16_t i=0; i<256; i++) { + if(i == '\n') display.write(' '); + else display.write(i); + } + + display.display(); } +void setup() { + pinMode(SORTIE_RELAIS, OUTPUT); + digitalWrite(SORTIE_RELAIS, LOW); + + Wire.begin(SDA, SCL); // join i2c bus (address optional for master) + Serial.begin(115200); // start serial for output + + // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally + if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { + Serial.println(F("SSD1306 allocation failed")); + for(;;); // Don't proceed, loop forever + } + + // Clear the buffer + display.clearDisplay(); + + // Show the 'K' splash screen + display.drawBitmap( + (display.width() - LOGO_WIDTH ) / 2, + (display.height() - LOGO_HEIGHT) / 2, + bitmap_K, LOGO_WIDTH, LOGO_HEIGHT, 1); + display.display(); + delay(2000); + + // Clear the buffer + display.clearDisplay(); +} void loop() { - digitalWrite(SORTIE_ALIM, HIGH); + digitalWrite(SORTIE_RELAIS, HIGH); for (int i = count; i > 0; i--) { - char cstr[16]; - itoa(i, cstr, 10); + display.clearDisplay(); - myOLED.setFont(BigNumbers); - myOLED.clrScr(); - myOLED.print(cstr, CENTER, 0); - myOLED.update(); + display.setTextSize(6); // Normal 1:1 pixel scale + display.setTextColor(SSD1306_WHITE); // Draw white text + display.setCursor(0, 20); // Start at top-left corner + + display.println(i); + display.display(); + display.startscrollright(0x00, 0x0F); delay(1000); } - - myOLED.setFont(SmallFont); - myOLED.clrScr(); - myOLED.print("OFF", CENTER, 0); - myOLED.update(); - digitalWrite(SORTIE_ALIM, LOW); - delay(1000); -} \ No newline at end of file + + display.clearDisplay(); + display.display(); + digitalWrite(SORTIE_RELAIS, LOW); + delay(3000); +}