Last active
June 24, 2020 15:53
-
-
Save Franck1333/133faba76fa7695bb177bbba9376cf86 to your computer and use it in GitHub Desktop.
Arduino : OLED Display with U8G's/Adafruit's libs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //This example has to be used with any SSD1306 screen Vertical/Horizontal screen with ~1" spec. | |
| //This example use the Adafruits libs. | |
| //AIDE: http://adafruit.github.io/Adafruit_SSD1306/html/index.html | |
| //AIDE: https://projetsdiy.fr/ssd1306-mini-ecran-oled-i2c-128x64-arduino/ | |
| #include <SPI.h> | |
| #include <Wire.h> | |
| #include <Adafruit_GFX.h> | |
| #include <Adafruit_SSD1306.h> | |
| #define SCREEN_WIDTH 128 // OLED display width, in pixels | |
| #define SCREEN_HEIGHT 32 // OLED display height, in pixels | |
| // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) | |
| #define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin) | |
| Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); | |
| void setup() { | |
| Serial.begin(9600); | |
| //---INIT_SCREEN--- | |
| // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally | |
| if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32 | |
| Serial.println(F("SSD1306 allocation failed")); | |
| for(;;); // Don't proceed, loop forever | |
| } | |
| // Show initial display buffer contents on the screen -- | |
| // the library initializes this with an Adafruit splash screen. | |
| display.display(); | |
| // Clear the buffer | |
| display.clearDisplay(); | |
| delay(2048); | |
| // display.display() is NOT necessary after every single drawing command, | |
| // unless that's what you want...rather, you can batch up a bunch of | |
| // drawing operations and then update the screen all at once by calling | |
| // display.display(). These examples demonstrate both approaches... | |
| //---INIT_SCREEN--- | |
| HelloWorld(); | |
| } | |
| void loop() { | |
| // put your main code here, to run repeatedly: | |
| } | |
| void HelloWorld(void){ | |
| Serial.println("HelloWorld!!!"); //Message visible dans la console | |
| display.setTextColor(WHITE); // La couleur du texte | |
| display.setCursor(0,0); // On va ecrire en x=0, y=0 | |
| display.print("Hello,"); // Un println pour écrire du texte sur l'ecran | |
| display.println(" world!"); | |
| display.display(); // Affichage du Resultat | |
| } | |
| void TestLigneAffichage(void){ | |
| Serial.println("Teste d'affichage de l'ecran OLED."); //Message visible dans la console | |
| display.setTextColor(WHITE); // La couleur du texte | |
| display.setCursor(0,0); // On va ecrire en x=0, y=0 | |
| display.print("Ligne d'affichage 1"); // Un println pour écrire du texte sur l'ecran | |
| display.setTextColor(WHITE); // La couleur du texte | |
| display.setCursor(0,10); // On va ecrire en x=0, y=0 | |
| display.print("Ligne d'affichage 2"); // Un println pour écrire du texte sur l'ecran | |
| display.setTextColor(WHITE); // La couleur du texte | |
| display.setCursor(0,20); // On va ecrire en x=0, y=0 | |
| display.print("Ligne d'affichage 3"); // Un println pour écrire du texte sur l'ecran | |
| display.setTextColor(WHITE); // La couleur du texte | |
| display.setCursor(0,30); // On va ecrire en x=0, y=0 | |
| display.print("Ligne d'affichage 4"); // Un println pour écrire du texte sur l'ecran | |
| display.display(); // Affichage du Resultat | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "U8glib.h" | |
| U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); //Constructeur de mon ecran a moi | |
| void draw() { | |
| // graphic commands to redraw the complete screen should be placed here | |
| u8g.setFont(u8g_font_7x13); //Police d'affichage compacte | |
| int flux = analogRead(A5); //Lecture du Pin Analogique A5 du Potentiometre | |
| Serial.println("La Valeur du Potentionmetre est de : "); //Affichage dans la console serie | |
| Serial.println(flux); //Affichage dans la console serie | |
| u8g.drawStr( 30, 10, "Hello world!"); //Affichage sur l'ecran OLED d'une chaine de caractere | |
| u8g.setPrintPos(0, 50); //Positionnement du curseur pour afficher autre chose... | |
| u8g.print(flux); //A la position du curseur, affichage de la variable "flux". | |
| } | |
| void setup(void) { | |
| u8g.setColorIndex(1); // white | |
| Serial.begin(9600); //Initialisation de la communication serie pour la console | |
| pinMode(A5,OUTPUT); //Initialisation du Pin A5 Analogique pour le Potentiomètre | |
| } | |
| void loop(void) { | |
| // picture loop | |
| u8g.firstPage(); | |
| do { | |
| draw(); | |
| } while( u8g.nextPage() ); | |
| // rebuild the picture after some delay | |
| delay(1000); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment