Este es el código que tengo hasta el momento:
/*
© Mauricio Araya
mjaraya@gmail.com
rev 0.1.0
*/
#include <SoftwareSerial.h>
#include <Nextion.h>
SoftwareSerial nextion(2, 3);// Nextion TX to pin 2 and RX to pin 3 of Arduino
Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps
const int BEEP = 12; //Pin definition Piezo Speaker
const int STARTBUTTON = 8; //Pin definition for Start push button
const int LIGHT = 13; //Pin definition for the light
boolean bFocusState; //to store the Focus button state for toggle
float baseExp; //base exposure calculation
float initBaseExp = 3.0; //initial base exposure in steps
float fStopInc = 0.3333; //initial fstop increment
float fTime;
//function to show the Fstop Increment
void showFincrement(float BE) {
char buffer[10];
dtostrf(BE, 5, 1, buffer); // Prints "baseExp"
myNextion.setComponentText("tBE", buffer);
Serial.print("baseExposition: ");
Serial.println(BE);
}
//function to show the base exposure (seconds)
float showFtime (float BE) {
fTime = pow(2,BE); //0.1 is added because the arduino rounding function
char buffer[10];
dtostrf(fTime, 5, 1, buffer); // Prints "baseExp"
myNextion.setComponentText("tfStopTime", buffer);
Serial.print("fStopTime: ");
Serial.println(fTime, 1);
}
//function to show the base exposure (seconds) countdown
float showFtimeCount (float FT) {
char buffer[10];
dtostrf(FT, 5, 1, buffer); // Prints "baseExp"
myNextion.setComponentText("tfStopTime", buffer);
Serial.print("fStopTime: ");
Serial.println(FT, 1);
}
//function to convert the int to char and show the base exposure
void showBaseExp(float BE) {
char buffer[10];
dtostrf(BE, 5, 1, buffer); // Prints "baseExp"
myNextion.setComponentText("tBE", buffer);
Serial.print("baseExposition: ");
Serial.println(BE);
}
void setup() {
Serial.begin(9600);
myNextion.init();
//pin asignment
pinMode(STARTBUTTON, INPUT);
pinMode(BEEP, OUTPUT);
pinMode(LIGHT, OUTPUT);
//initial values on screen
myNextion.setComponentValue("nDecimas", 10);
myNextion.setComponentText("t4", "1/3");
baseExp = initBaseExp;
showBaseExp(initBaseExp);
showFtime(initBaseExp);
}
void loop() {
//check for message
String message = myNextion.listen();
//Serial.println(message);
//Increase or decrease the Base Expo
if (message == "65 0 4 0 ffff ffff ffff") { //+ button
baseExp += fStopInc;
showBaseExp(baseExp);
showFtime(baseExp);
} else if (message == "65 0 5 0 ffff ffff ffff") { //- button
baseExp -= fStopInc;
showBaseExp(baseExp);
showFtime(baseExp);
}
//Increase or decrease Fstop Increment
if (message == "65 0 6 0 ffff ffff ffff") { //+ button
} else if (message == "65 0 7 0 ffff ffff ffff") { //- button
}
//Start runing countdown:
if ((message == "65 0 1 0 ffff ffff ffff") || digitalRead(8) == HIGH) { //if Start button is pressed
//myNextion.buttonToggle(bStartState, "bFocus", 0, 2);
for (float i=fTime; i>0; i) {
message = myNextion.listen();
if (message == "65 0 1 0 ffff ffff ffff") {
/for (int j=1; j=0; j){
Serial.println(fTime, 1);
message = myNextion.listen();
if (message == "65 0 1 0 ffff ffff ffff") {
//myNextion.buttonToggle(bStartState, "bFocus", 0, 2);
j--;
}//if
}//for/
Serial.println("boton");
}//if
Serial.println(fTime, 1);
digitalWrite(LIGHT, HIGH);
showFtimeCount(fTime);
delay(55);
i=i-0.1;
fTime = fTime - .1;
}//for
digitalWrite(LIGHT, LOW);
showFtime(baseExp);
}//if
//Turn on and off Focus:
if (message == "65 0 25 0 ffff ffff ffff" ) {
myNextion.buttonToggle(bFocusState, "bFocus", 0, 2); //Toggle focus button
if (bFocusState == HIGH) {
//Turn Relay on:
digitalWrite(LIGHT, HIGH);
} else {
//Turn Relay off:
digitalWrite(LIGHT, LOW);
}
}
}