hola un gran saludo ,
Resolviendo casi todo los inconveniente que tuve desde que postee , he ido resolviendo ylos problemas que se me habian ido presentndo uno seria las grabacion de los valores min , max en la eeprom solo q me surgio otro problemitaque al guardar un valor tengo q ejecutar 2 veces en modo de seleccion para q se guarde q es el valor de rango max ac ( 120 ) , q podria ser ¿¿
sigo pidiendo sugerencia con el uso de los botones , con los rebotes , delay mal puestos , mejorar la estructura al grabar los datos
he cambiado alguna cosa
codigo seria
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int upButton = 6;
int downButton = 7;
int selectButton = 8;
int grabartBtn = 9;
//int NavgLeftBtn = 9;
//int NavgRightBtn = 10;
int td = 100;
int nPulso;
unsigned long time ;
unsigned long t = 0;
int dt = 150;
int adjV1MIN ;
int adjV1MAX ;
int adjV2MIN ;
int adjV2MAX ;
void setup ()
{
adjV1MIN = 90; // VOLTAJE FASE1 MIN
adjV1MAX = 150; // VOLTAJE FASE1 MAX
adjV2MIN = 190; // VFASE2
adjV2MAX = 250; // VFASE2
lcd.begin();
lcd.backlight();
// pinMode (led, OUTPUT);
pinMode(upButton, INPUT_PULLUP);
pinMode(downButton, INPUT_PULLUP);
pinMode(selectButton, INPUT_PULLUP);
pinMode(grabartBtn, INPUT_PULLUP);
// pinMode(NavgLeftBtn, INPUT_PULLUP);
// pinMode(NavgRightBtn, INPUT_PULLUP);;
Serial.begin(9600); // inicializa monitor serie a 9600 bps
EEPROM.get(0, adjV1MIN);
EEPROM.get(4, adjV1MAX);
EEPROM.get(8, adjV2MIN);
EEPROM.get(12, adjV2MAX);
// Serial.println( EEPROM.get(0, adjV1MIN) );
// Serial.println( EEPROM.get(4, adjV1MAX) );
// Serial.println( EEPROM.get(8, adjV2MIN) );
// Serial.println( EEPROM.get(12, adjV2MAX) );
//
// Serial.println(" "); // espacio en blanco
// updatedatos();
}
void loop ()
{
// Serial.println (millis());
time = millis();
if (time - t > dt) {
t = time;
if (!digitalRead(selectButton)) {
nPulso ++;
while (!digitalRead(selectButton));
}
if (nPulso == 0)
if (!digitalRead(upButton)) {
if ( adjV1MIN <= 105) {
adjV1MIN = adjV1MIN + 5;
// EEPROM.put(0, adjV1MIN);
lcd.setCursor(12, 2);
lcd.print((char)126);
}
while (!digitalRead(upButton));
}
else if (!digitalRead(downButton))
{
if ( adjV1MIN >= 95) {
adjV1MIN = adjV1MIN - 5;
// EEPROM.put(0, adjV1MIN);
lcd.setCursor(12, 2);
lcd.print((char)127);
}
while (!digitalRead(downButton));
}
if (nPulso == 1) // VALOR MAX
if (!digitalRead(upButton)) {
if ( adjV1MAX >= 135) {
adjV1MAX = adjV1MAX - 5;
lcd.setCursor(12, 2);
lcd.print((char)127);
}
while (!digitalRead(upButton));
}
if (!digitalRead(downButton))
{
if ( adjV1MAX <= 145) {
adjV1MAX = adjV1MAX + 5;
lcd.setCursor(12, 2);
lcd.print((char)126);
}
while (!digitalRead(downButton));
}
if (nPulso == 2)
if (!digitalRead(upButton)) {
if ( adjV2MIN <= 205) {
adjV2MIN = adjV2MIN + 5;
lcd.setCursor(12, 2);
lcd.print((char)126);
}
// Serial.print (nPulso);
while (!digitalRead(upButton));
}
else if (!digitalRead(downButton))
{
if ( adjV2MIN >= 195) {
adjV2MIN = adjV2MIN - 5;
lcd.setCursor(12, 2);
lcd.print((char)127);
}
while (!digitalRead(downButton));
}
if (nPulso == 3)
if (!digitalRead(upButton)) {
if ( adjV2MAX >= 235) {
adjV2MAX = adjV2MAX - 5;
lcd.setCursor(12, 2);
lcd.print((char)127);
}
// Serial.print (nPulso);
while (!digitalRead(upButton));
}
else if (!digitalRead(downButton))
{
if ( adjV2MAX <= 245) {
adjV2MAX = adjV2MAX + 5;
lcd.setCursor(12, 2);
lcd.print((char)126);
}
while (!digitalRead(downButton));
}
if (nPulso == 4)
if (!digitalRead(grabartBtn)) {
updatedatos();
lcd.clear();
lcd.setCursor(5, 2);
lcd.print ("GUARDANDO");
lcd.setCursor(0, 1);
lcd.print ("."); // efecto de barra
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
delay(td);
lcd.print (".");
while (!digitalRead(grabartBtn));
lcd.clear();
nPulso = 0;
}
if (nPulso == 5) // vuelve al inicio.
nPulso = 0;
updateMenu();
}
}
void updateMenu() {
switch (nPulso) // definido 4 cases.
{
case 0:
// lcd.clear();
lcd.setCursor(1, 1);
lcd.print("[AJUSTE FASE 120]");
lcd.setCursor(0, 2);
lcd.print("> RANGO Min");
lcd.setCursor(16, 2);
lcd.print(" ");
lcd.setCursor(15, 2);
lcd.print (adjV1MIN);
break;
case 1:
// lcd.clear();
lcd.setCursor(1, 1);
lcd.print("[AJUSTE FASE 120]");
lcd.setCursor(0, 2);
lcd.print("> RANGO Max");
lcd.setCursor(15, 2);
lcd.print (adjV1MAX);
break;
case 2:
// lcd.clear();
lcd.setCursor(1, 1);
lcd.print("[AJUSTE FASE 220]"); //alt 126 249
lcd.setCursor(0, 2);
lcd.print("> RANGO Min");
lcd.setCursor(15, 2);
lcd.print (adjV2MIN);
break;
case 3:
// lcd.clear();
lcd.setCursor(1, 1);
lcd.print("[AJUSTE FASE 220]");
lcd.setCursor(0, 2);
lcd.print("> RANGO Max");
lcd.setCursor(15, 2);
lcd.print (adjV2MAX);
break;
case 4:
// lcd.clear();
lcd.setCursor(1, 1);
lcd.print (" PRESIONE GUARDAR ");
lcd.setCursor(1, 1);
lcd.print ("");
lcd.setCursor(0, 2);
lcd.print (" ");
// nPulso = 4 ;
break;
}
}
void updatedatos() {
if (nPulso == 4)
EEPROM.put(0, adjV1MIN);
EEPROM.put(4, adjV1MAX);
EEPROM.put(8, adjV2MIN);
EEPROM.put(12, adjV2MAX);
}