Changement librairie oled : Adafruit

This commit is contained in:
Laurent Claude 2023-09-02 23:58:11 +02:00
parent b62acfc56e
commit aaa3086c56
2 changed files with 95 additions and 38 deletions

View File

@ -13,5 +13,5 @@ platform = espressif32
board = esp32cam board = esp32cam
framework = arduino framework = arduino
lib_deps = lib_deps =
poma/OLED_I2C @ ^2.12 adafruit/Adafruit SSD1306@^2.5.7
adafruit/Adafruit GFX Library@^1.11.7

View File

@ -1,55 +1,112 @@
#include <Arduino.h>
//#include <Wire.h> #include <SPI.h>
#include <OLED_I2C.h> #include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#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 SDA 12
#define SCL 13 #define SCL 13
OLED myOLED(SDA, SCL); #define SORTIE_RELAIS 2
extern uint8_t BigNumbers[];
extern uint8_t SmallFont[];
#define SORTIE_ALIM 4
#define LED_FLASH 4 #define LED_FLASH 4
#define LED_BUILTIN 33 #define LED_BUILTIN 33
#define MyLED LED_FLASH
int count = 7;
bool sortieAlim = false;
void setup() { // durée par défaut en secondes
pinMode(SORTIE_ALIM, OUTPUT); int count = 12;
digitalWrite(SORTIE_ALIM, LOW);
myOLED.begin(SSD1306_128X32); #define LOGO_HEIGHT 32
myOLED.setFont(SmallFont); #define LOGO_WIDTH 32
myOLED.clrScr(); const unsigned char bitmap_K [] PROGMEM = {
myOLED.print("Hello", CENTER, 0); //uint8_t bitmap_K [] PROGMEM = {
myOLED.update(); // 'K, 32x32px
delay(1000); 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() { void loop() {
digitalWrite(SORTIE_ALIM, HIGH); digitalWrite(SORTIE_RELAIS, HIGH);
for (int i = count; i > 0; i--) for (int i = count; i > 0; i--)
{ {
char cstr[16]; display.clearDisplay();
itoa(i, cstr, 10);
myOLED.setFont(BigNumbers); display.setTextSize(6); // Normal 1:1 pixel scale
myOLED.clrScr(); display.setTextColor(SSD1306_WHITE); // Draw white text
myOLED.print(cstr, CENTER, 0); display.setCursor(0, 20); // Start at top-left corner
myOLED.update();
display.println(i);
display.display();
display.startscrollright(0x00, 0x0F);
delay(1000); delay(1000);
} }
myOLED.setFont(SmallFont); display.clearDisplay();
myOLED.clrScr(); display.display();
myOLED.print("OFF", CENTER, 0); digitalWrite(SORTIE_RELAIS, LOW);
myOLED.update(); delay(3000);
digitalWrite(SORTIE_ALIM, LOW);
delay(1000);
} }