Si ça intéresse quelqu'un ou bien donne des idées:
// Sonde pression1301 fonctionnelle
// sonde température Zeitronix fonctionnelle, sonde grove fonctionnelle
// Intro Subaru
// variation affichage avec bouton
// RPM par prise signal sur alim compt tours
// Thuile ok à 75°
// Thuile chaude à 120° et trop chaude à 140°
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
byte subaru1[8] = {
B00100,
B00100,
B01110,
B11111,
B01110,
B00100,
B00100,
B00000
};
byte subaru2[8] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00010,
B00111,
B00010
};
byte subaru3[8] = {
B00000,
B00000,
B00000,
B00010,
B00111,
B00010,
B00000,
B00000
};
byte subaru4[8] = {
B01000,
B11100,
B01000,
B00010,
B00111,
B00010,
B00000,
B00000
};
byte subaru5[8] = {
B01000,
B11100,
B01000,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte subaru6[8] = {
B10000,
B01000,
B00100,
B00010,
B00010,
B00001,
B00001,
B00001
};
byte subaru7[8] = {
B00001,
B00001,
B00001,
B00010,
B00010,
B00100,
B01000,
B10000
};
int ledRougePin = 4;
int ledVertPin = 5;
int ledBleuPin = 6;
float Thuile=0;
float Phuile=0;
float volthuile=0;
float varThuile=1;
int c=0;
int x=0;
int y=0;
int z=0;
float psi=0;
float voltPhuile=0;
float tempin; //calcul température habitacle
int B=3975; //calcul température habitacle
float resistance; //calcul température habitacle
float Thuilemax=-50;
float Phuilemax=0;
float Phuilemin=10;
int bouton=0;
#define valeurMax 6
const char* TempIn="T. In";
const char* TempEx="T. Ex";
const char* Batt="Batt.";
const char* Rpm="RPM";
char Unite='0';
const char* Intitule=0;
float t=0;
int RPM=0;
float RPMfloat=0;
int ledRPMPin = 2;
const int numReadingsR = 1500 ; // Nombre de relevés pour la moyenne rpm
int readingsR ; // Variable lecture pour le relevé tension
int indexR = 0 ; // position dans la création de la moyenne
float totalR = 0 ; // Total en cours
float averageR = 0 ; // La moyenne
void setup(){
pinMode(3, OUTPUT); // 5V pour rétroéclairage (option variation d'intensité)
digitalWrite(3, HIGH);
lcd.begin(16, 2); // paramètre lcd
pinMode(13,INPUT); // bouton sur pin 13
digitalWrite(13, HIGH); // alimentation pin 13
pinMode( ledRougePin, OUTPUT );
pinMode( ledVertPin, OUTPUT );
pinMode( ledBleuPin, OUTPUT );
pinMode( ledRPMPin, OUTPUT );
digitalWrite( ledRougePin, HIGH );
digitalWrite( ledVertPin, HIGH );
digitalWrite( ledBleuPin, HIGH );
lcd.clear();
lcd.createChar(1, subaru1);
lcd.createChar(2, subaru2);
lcd.createChar(3, subaru3);
lcd.createChar(4, subaru4);
lcd.createChar(5, subaru5);
lcd.createChar(6, subaru6);
lcd.createChar(7, subaru7);
lcd.setCursor(0,0);
lcd.print((char)1); lcd.print((char)2);
lcd.setCursor(3,0); lcd.print((char)6);
lcd.setCursor(3,1); lcd.print((char)7);
lcd.setCursor(6,0); lcd.print("SUBARU");
lcd.setCursor(0,1); lcd.print((char)3);lcd.print((char)4); lcd.print((char)5);
delay(3000); // Ecran vide 5 seconde
lcd.clear();
for (int positionCounter = 0; positionCounter < 12; positionCounter++) {
// Décalle le curseur de 12 colonnes vers la gauche
lcd.scrollDisplayLeft();
}
lcd.print("LEGACY TURBO");
for (int positionCounter = 0; positionCounter < 14; positionCounter++) {
// Décalle le texte vers la droite et le centre
lcd.scrollDisplayRight();
// wait a bit:
delay(150); }
// Réinitialisation de l'affichage et de la position du curseur
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" LEGACY TURBO");
delay(1000);
lcd.setCursor(16,1);
lcd.print("Bienvenue a bord");
for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
// scroll one position right:
lcd.scrollDisplayLeft();
// wait a bit:
delay(150); }
lcd.clear();
lcd.setCursor(2,0);
lcd.print("LEGACY TURBO");
lcd.setCursor(0,1);
lcd.print("Bienvenue a bord");
delay(2000);
lcd.clear();
}
void loop(){
// Interprétation sonde temperature grove
resistance=(float)(1023-analogRead(A4))*10000/analogRead(A4);
tempin=1/(log(resistance/10000)/B+1/298.15)-273.15;
volthuile=analogRead(A1)*5.0/1024.0;
varThuile=0.5608*volthuile+1.4498;
if(varThuile<2.02){Thuile=((440.12*pow(volthuile,4)-1493.9*pow(volthuile,3)+1881.8*pow(volthuile,2)-1083.8*volthuile+335.06))/varThuile;}
if(varThuile>2.02){Thuile=((0.1541*pow(volthuile,4)-2.6435*pow(volthuile,3)+17.306*pow(volthuile,2)-60.03*volthuile+124.59))/varThuile;}
voltPhuile=analogRead(A0)*5.0/1024.0;
psi=(37.5*(voltPhuile))-18.75;
Phuile=psi/14.51; // conversion en bar
if (Phuile<0) {Phuile==0;}
if(Thuile<75) {Thuilefroide();}
if(Thuile>75 and Thuile<110) {Thuileok();}
if(Thuile>115 and Thuile<130) {Thuilechaude();}
if(Thuile>130) {Thuiletropchaud();}
if (Thuile>Thuilemax) {Thuilemax=Thuile;}
if (Phuile>Phuilemax) {Phuilemax=Phuile;}
if (Phuile<Phuilemin) {Phuilemin=Phuile;}
// Convertir le signal du compte tours (moyenné pour lisser l'affichage)
while(indexR< numReadingsR) {
readingsR = analogRead (5) ;
totalR = totalR + readingsR ;
indexR = indexR + 1 ; }
indexR = 0 ;
averageR = totalR / numReadingsR ;
RPMfloat=averageR*10.3;
RPMfloat=RPMfloat/10;
RPM=RPMfloat;
RPM=RPM*10;
totalR=0;
if(RPM<=6000) {delay(200);}
if(RPM>6800) {delay(300);}
if(RPM>6000 and RPM<6800) { for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=50) {
analogWrite(ledRPMPin, fadeValue);
delay(10);
}
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=50) {
// sets the value (range from 0 to 255):
analogWrite(ledRPMPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
} }
if(RPM>6800) {digitalWrite(2, HIGH); }
if (digitalRead(13)==HIGH) // incrément x par appui bouton
{ lcd.clear();
if (bouton<valeurMax){ bouton++;} else {bouton=0;}
delay(200);
while((digitalRead(13)==HIGH));
}
switch (bouton) { // en fonction de la valeur de x, on modifie l'affichage
case 0: Intitule=Batt; t=0; Unite='V'; break;
case 1: Intitule=TempIn; t=tempin; Unite=(char)223; break;
case 2: Intitule=TempEx; t=0; Unite=(char)223; break;
case 3: Intitule=Rpm; t=RPM; Unite=' '; break;
case 4: lcd.setCursor(0,0); lcd.print("T huile maxi:");
lcd.setCursor(0,1); lcd.print(Thuilemax);
lcd.print((char)223); lcd.print("C"); break;
case 5: lcd.setCursor(0,0); lcd.print("P huile maxi:");
lcd.setCursor(0,1); lcd.print(Phuilemax);
lcd.print("b"); break;
case 6: lcd.setCursor(0,0); lcd.print("P huile mini.");
lcd.setCursor(0,1); lcd.print(Phuilemin);
lcd.print("b"); break;}
// Affichage sur lcd
if (bouton<4) {
lcd.clear();
lcd.setCursor(0,0); lcd.print("OilT");
lcd.setCursor(6,0); lcd.print("OilP");
lcd.setCursor(11,0); lcd.print(Intitule);
lcd.setCursor(0,1);
if(Thuile<100) {lcd.print(Thuile, 1);} else {lcd.print(Thuile, 0);}
lcd.print((char)223);
lcd.setCursor(6,1); lcd.print(Phuile, 1); lcd.print("b");
lcd.setCursor(11,1);
if(Intitule==Batt || Intitule==TempEx) {lcd.print(" No");}
if(Intitule==TempIn){lcd.print(t, 1);}
if(Intitule==Rpm){lcd.print(t, 0);}
if(Intitule==TempIn || Intitule==Rpm){lcd.print(Unite);}
}
delay(50);
}
void Thuilefroide(){
int iBleu = Thuile*3.1875; iBleu>0;
int iVert = 255 - iBleu;
analogWrite( ledBleuPin, iBleu );
analogWrite( ledVertPin, iVert );
}
void Thuileok(){
digitalWrite( ledRougePin, HIGH );
digitalWrite( ledVertPin, HIGH );
digitalWrite( ledBleuPin, HIGH );
if (y==0) {
x=0;
y++;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" GO ");
for (x==0; x<6; x++) {
lcd.setCursor(0,1);
lcd.print(" ! ! ! ! ! ! ");
delay(250);
lcd.clear(); lcd.setCursor(0,0); lcd.print(" GO ");
delay(250); lcd.setCursor(0,1); lcd.print(" ! ! ! ! ! ! "); }
}}
void Thuilechaude(){
int iVert = Thuile*6-593; iVert>127;
analogWrite( ledRougePin, 0 );
analogWrite( ledVertPin, iVert );
}
void Thuiletropchaud(){
digitalWrite( ledRougePin, LOW );
digitalWrite( ledVertPin, HIGH );
digitalWrite( ledBleuPin, HIGH );
if (z==0) {
x=0;
z++;
lcd.print("ARRET IMPERATIF");
for (x==0; x<6; x++) {
lcd.setCursor(0,1);
lcd.print(" ! ! ! ! ! ! ");
delay(250);
lcd.clear(); lcd.setCursor(0,0); lcd.print("ARRET IMPERATIF");
delay(250); lcd.setCursor(0,1); lcd.print(" ! ! ! ! ! ! ");}
}}