Buenas tardes. Hacia tiempo que no aparecía por aquí ya que no tenia nada entre manos pero llevo 2 o 3 semanas con un pequeño proyecto para el curro , algo que necesito para realizar unas pruebas y estoy atascado. Os cuento, la idea es utilizar un Arduino nano para medir presión y vacío. Los código por separado funcionan a falta de ajustarlos con medidores patrones. El problema esta en que quiero meter los dos codigos juntos separados solo por un boton de seleccion cada uno.... sin grandes historias de menús ni nada, seleccionar cada magnitud con un botón individual( si quiero presion pulso un botón y si quiero vacio pulso el otro botón).
Lo cierto es que cuando lo meto en el " if " el código no corre. si dejo pulsado el botón si pero si no...se congela . Llevo un par de semanas trasteando por el foro, internet y youtube y no he vito nada que me sirva cada vez que intento implementar el código de medición obtengo el mismo resultado. A ver si podeis echarme una mano. Gracias por adelantado.
Eliminando el [delay(50);] final me hace lo mismo.
El codigo que paso es solo para la medicion de presion para no alargar demasiado ....
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <BigFont01_I2C.h>
LiquidCrystal_I2C lcd (0x27, 20, 4);
BigFont01_I2C big(&lcd);
const int analogInPin = A0; // Pin Analogico al que esta conectado el sensor
int sensorValue = 0; // Valor leido
float PresionValue = 0;
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
Serial.begin(9600); // inicializa comunicacion serial a 9600 baudios
lcd.init();
lcd.backlight();
big.begin();
lcd.clear();
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
presion();
//else {
// turn LED off:
// digitalWrite(ledPin, LOW);
//}
}
void presion()
{
sensorValue = analogRead(analogInPin); //Lee el valor analogico
PresionValue = ((map(sensorValue, 102, 920, 0, 20000))/100.0)/14.5038; //Calcula los bares
int parteEnteraPresion = int(PresionValue);
float parteDecimalPresion = PresionValue -parteEnteraPresion;
int parteDecimal100 = int (parteDecimalPresion*100);
//Imprime los resultados por monitor serial:
Serial.print("Valor ADC = ");//
Serial.print(sensorValue); //
Serial.print("\t bar = "); //
Serial.println(PresionValue); //
//Imprime los resultados por monitor serial:
lcd.setCursor(0,0);
lcd.print("PRESION: ");
lcd.setCursor(2,4);
big.writeint(2,4,parteEnteraPresion,1,true);
big.writechar(2, 7, '.');
big.writeint(2, 10, parteDecimal100, 2, true);
lcd.setCursor(17, 3);
lcd.print("bar");
//lcd.print(PresionValue,3);
delay(50); //retardo
}