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
| #include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <U8g2lib.h>
// Afficheur OLED
#define SCREEN_WIDTH 128 // Ecran OLED 128 pixels de long
#define SCREEN_HEIGHT 64 // Ecran OLED 64 pixels de haut
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Afficheur graphique
U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, 13, 11, 10, 8);
void setup()
{
Serial.begin(9600);
u8g2.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
display.clearDisplay();
}
void loop()
{
display.display();
display.clearDisplay(); //Efface l'écran et le tampon
display.setTextSize(1); // Taille du texte
display.setTextColor(WHITE);
display.setCursor(0, 1);
display.print("Hello world");
display.setCursor(0, 40);
display.print(millis() / 1000);
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(0, 24, "Hello World!");
}
while ( u8g2.nextPage() );
} |