Bonjour;
Je vous expose mon projet un tableau de bord avec 4 interrupteurs une sonde de température et un contrôleur de charge.
je suis très novice en codage j'ai utilisé 2 exemples existants que j'ai rassemblés mais là je suis bien bloqué.
-Les 4 interrupteurs pour les 4 relais ok
-la sonde de température pour eguille ça fonctione mais je navire par a afficher la temperature en numérique.
-le voltmetre en cours chaque chose en sont temps
Merci beaucoup pour votre aide
#include "EasyNextionLibrary.h"
#define baudrate 9600
EasyNex myNex(Serial);
//Variables
uint16_t analog;
uint16_t voltage;
bool ledstate;
const int REFRESH_TIME = 100;
unsigned long refresh_timer = millis();
//
void setup() {
myNex.begin(9600);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
//
void loop(){
myNex.NextionListen(); // WARNING: This function must be called repeatedly to response touch events
// from Nextion touch panel. Actually, you should place it in your loop function.
if((millis()-refresh_timer) > REFRESH_TIME){ //IMPORTANT do not have serial print commands in the loop without a delay
// or an if statement with a timer condition like this one.
int tempData = analogRead(A1); // Read the analog pin
voltage = map(tempData, 0, 1024, 0, 5000); // same like: voltage = analogRead(A0)*5000/1024
/* We Re-map the value of tempData from 0-1024 (steps) to 0-5000 millivolt
* connect the pins of a Potentiometer on A0 pin, 5v (5000 millivolt) and GND. Outer pins to 5v and GND, middle pin to A0
* https://www.arduino.cc/en/tutorial/potentiometer
* Turn it over and read values from 0 to 5000 millivolts
*/
myNex.writeNum("Nvoltage.val", voltage); // Nvoltage.val is a variable that we have create on Nextion.
// we send the value of the voltage variable on Arduino
// you can use the same name for variables on Nextion for easy recognition with a capital N in front
// Avoid the use of big variable names as every character is one byte to serial.
// In here we use big names for the sake of example.
refresh_timer = millis(); // Set the timer equal to millis, create a time stamp to start over the "delay"
}
}
void trigger1(){
// To call this void send from Nextion's component's Event: printh 23 02 54 01
// In this exmaple, we send this command from the Release Event of b1 button (see the HMI of this example)
// You can send the same `printh` command, to call the same function, from more than one component, depending on your needs
digitalWrite(6, !digitalRead(6)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
if(digitalRead(6) == HIGH){
myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
}else if(digitalRead(7) == LOW){
myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
}
}
void trigger2(){
/* Create a button on Nextion
* Write in the Touch Release Event of the button
* this command: printh 23 02 54 00
* Every time the button is pressed, the trigger0() function will run
* and the code inside will be executed once
*/
digitalWrite(7, !digitalRead(7)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
if(digitalRead(7) == HIGH){
myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
}else if(digitalRead(7) == LOW){
myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
}
}
void trigger3(){
/* Create a button on Nextion
* Write in the Touch Release Event of the button
* this command: printh 23 02 54 00
* Every time the button is pressed, the trigger0() function will run
* and the code inside will be executed once
*/
digitalWrite(8, !digitalRead(8)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
if(digitalRead(8) == HIGH){
myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
}else if(digitalRead(8) == LOW){
myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
}
}
void trigger4(){
/* Create a button on Nextion
* Write in the Touch Release Event of the button
* this command: printh 23 02 54 00
* Every time the button is pressed, the trigger0() function will run
* and the code inside will be executed once
*/
digitalWrite(9, !digitalRead(9)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
if(digitalRead(9) == HIGH){
myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
}else if(digitalRead(9) == LOW){
myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
}
}
et pour les code nextion
n0.val=Nvoltage.val // write Nvoltage.val to n0.val
sys0=Nvoltage.val*100/2800 // use sys0 to make the calculations
j0.val=120-sys0
if(n0.val<730)
{
j0.pco2=RED
}else
{
j0.pco2=GREEN
}
if(n0.val>1650)
{
j0.pco2=GRAY
}