Bonjour à tous
Je suis arrivé à faire fonctionner mon projet de thermomètre IR avec écran oled I2C 0.96 SSD1306 ainsi que 3 leds de niveaux de température.
Mon problème ai que je souhaite faire fonctionner mon application avec un écran plus grand de type oled I2C 1.3 SH1106 est là je n’arrive pas à configurer mon code
.
Pouvez-vous m’aider
En vous remerciant par avance.
Voici mon code actuel qui fonctionne avec la version oled I2C 0.96 SSD1306
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <stdint.h>
#include <Adafruit_MLX90614.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void setup() {
Serial.begin(57600);
Serial.println("Adafruit MLX90614 test");
mlx.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
// Initialisation de la LED
pinMode(9, OUTPUT); // Bleu
pinMode(10, OUTPUT); // Vert
pinMode(11, OUTPUT); // Rouge
// draw scrolling text
testscrolltext();
delay(500);
display.clearDisplay();
}
void loop() {
// Lecture de la température
float celsius = mlx.readObjectTempC();
// Re-etalonnage de la plage de temperature vers la plage de teinte
const float lowTemp = 26.0; // Temperature min (bleu)
const float highTemp = 33.0; // Temperature max (rouge)
const float lowHue = 240.0; // Couleur min (bleu)
const float highHue = 0; // Couleur max (rouge)
celsius = constrain(celsius, lowTemp, highTemp);
float hue = fmap(celsius, lowTemp, highTemp, lowHue, highHue);
// Modification de la couleur de la LED
float r, g, b;
HSVtoRGB(&r, &g, &b, hue, 1, 1);
setLeds(r * 255, g * 255, b * 255);
}
/** Applique les tensions sur les 3 broches de la LED */
void setLeds(byte r, byte g, byte b) {
// LED à anode commune
//analogWrite(9, 255 - b);
//analogWrite(10, 255 - g);
//analogWrite(11, 255 - r);
// LED à cathode commune
analogWrite(9, b);
analogWrite(10, g);
analogWrite(11, r);
}
/** Version float de la fonction Map */
float fmap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
/** Converti le modele de couleur HSV vers le modele RGB. Source : http://www.cs.rit.edu/~ncs/color/t_convert.html */
void HSVtoRGB(float *r, float *g, float *b, float h, float s, float v) {
int i;
float f, p, q, t;
if( s == 0 ) {
*r = *g = *b = v;
return;
}
h /= 60;
i = floor(h);
f = h - i;
p = v * (1 - s);
q = v * (1 - s * f);
t = v * (1 - s * ( 1 - f ));
switch(i) {
case 0:
*r = v;
*g = t;
*b = p;
break;
case 1:
*r = q;
*g = v;
*b = p;
break;
case 2:
*r = p;
*g = v;
*b = t;
break;
case 3:
*r = p;
*g = q;
*b = v;
break;
case 4:
*r = t;
*g = p;
*b = v;
break;
default:
*r = v;
*g = p;
*b = q;
break;
}
// Clear the buffer.
display.clearDisplay();
// text display tests
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("BOX");
display.setTextSize(2);
display.setCursor(70,0);
display.print(mlx.readAmbientTempC(), 0);
display.print("c");
display.setTextSize(2);
display.setCursor(0,18);
display.print("BELT");
display.setTextSize(2);
display.setCursor(70,18);
display.print(mlx.readObjectTempC(), 0);
display.print("c");
display.display();
delay(1000);
}
void testscrolltext(void) {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(-1,0);
display.println("Seb");
display.setTextSize(2);
display.setCursor(-1,18);
display.println("Racing");
display.display();
delay(1);
display.startscrollright(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(1000);
display.startscrollleft(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(1000);
display.stopscroll();
}
Thermo_led_1.ino (3.93 KB)