Bonjour à tous,
Je débute depuis peu avec l'Arduino et j'ai un problème avec mon écran Oled.
J'ai fait ce programme, mais dès que j'actualise l'affichage de l'écran, l'Arduino plante et le contenu de la boucle loop() n'est plus exécuté.
J'ai tenté avec un Arduino Uno et Mega mais le problème persiste.
#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 64 // 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);
#define NUMFLAKES 10
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
int PinCLK = 6;
int PinDT = 5;
int PinSW = 0;
int PinCLKLast = LOW;
int n = LOW;
int NbHeures = 1;
int WaitValidation = 0;
int ConfirmValidation = 0;
void setup() {
pinMode (PinCLK,INPUT);
pinMode (PinDT,INPUT);
pinMode (PinSW,INPUT);
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
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.
String heure = String(NbHeures);
testdrawstyles(heure);
}
void loop() {
Serial.println("Alive");
if (!(digitalRead(PinSW))) { // Reset la position si on appui sur le potentiomètre
if (WaitValidation == 0){
WaitValidation = 1;
String heure = String(NbHeures);
//FONCTION QUI CAUSE LE CRASH, UPDATE l'ECRAN
validation(heure);
}else{
}
}
n = digitalRead(PinCLK);
if (WaitValidation == 0){
if ((PinCLKLast == LOW) && (n == HIGH)) {
if (digitalRead(PinDT) == LOW) {
if (NbHeures < 24){
NbHeures ++;
String heure = String(NbHeures);
//FONCTION QUI CAUSE LE CRASH, UPDATE l'ECRAN
testdrawstyles(heure);
}
} else {
if (NbHeures > 1){
NbHeures --;
String heure = String(NbHeures);
//FONCTION QUI CAUSE LE CRASH, UPDATE l'ECRAN
testdrawstyles(heure);
}
}
}
}
PinCLKLast = n;
}
String testdrawstyles(String NbHour) {
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0,0); // Start at top-left corner
display.println(F("Test programme "));
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text
display.println("V.1.0.0-Alpha!");
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.print(F("Temps : "));
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.print(NbHour);
display.print(" Heures");
display.display();
}
String validation(String NbHour) {
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0,0); // Start at top-left corner
display.println(F("Test programme "));
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text
display.println("V.1.0.0-Alpha!");
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.print(F("VALIDER ? "));
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.print(NbHour);
display.print(" Heures");
display.display();
}
J'ai essayé mon programme en commentant les fonctions "testdrawstyles" ou "validation"
Les deux fonctions qui rafraichissent l'affichage de l'écran et la aucun crash. Dès que je remet ce code en place, dès que l'écran devra se rafraichir, la fonction s'exécutent bien, l'affichage de l'écran est mis à jour mais après l'Arduino est complètement planté.
Je ne sais pas d'ou pourrait venir ce problème ou si j'ai fait une erreur quelque part.
Merci d'avance pour votre aide.