Edition 1:
It seemed that the fault was a failure of wiring, which failed and from time to time makes a false contact.
After disconnecting the pin 0 and having nothing connected, you still make the same mistake.
End edition 1
I have a little silly mistake (I hope so) which jumps me by loading my code a few times , other times it works perfectly. For that reason I think it must be something that I have not noticed.
In this case I am connecting an electronic wallet to a Arduino UNO through the Digital Pin 2 .
The error occurs every time I load the code into the Arduino and restart it.
According to you when you have just loaded you can indicate on the screen Credit: 0.00 (which is what it should be) or you can put Credit: 0.10 .
If I always put 0.10, I could still understand that the failure is the first connection to the wallet, but by varying each time the failure is not ruled out.
I leave my code in case you see something that I can not locate:
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd (0x27, 20, 4);//en este caso una pantalla de 20x4
int pindeentrada = 0; //Monedero conectado a pin 2 (pin 2 es igual a 0)
volatile float montoTotal = 0.00;//variable que contara el monto
int deteccionDeCoin = 0;//Detector del Monedero electronico
void setup(){
digitalWrite(2, HIGH);
Serial.begin(9600);//Start Serial Communication
attachInterrupt(pindeentrada, insercionCredito, RISING);
Wire.begin();//PANTALLA
lcd.begin(20, 4);
lcd.clear();
lcd.backlight();
lcd.setCursor(0, 0);lcd.print("Credit: "); lcd.print(montoTotal);//FIN PANTALLA
}
void insercionCredito(){ //Esta funcion es la encargada de leer los pulsos del monedero
deteccionDeCoin = 1; //Actualizacion del detector del monnedero
}
void loop(){ //Bucle que actualiza el arduino
if(deteccionDeCoin == 1){ //Comprobacion del detector del monedero
montoTotal = montoTotal + 0.10; //esta variable suma en el monto total
lcd.clear();//pantalla
lcd.setCursor(0, 0);
lcd.print("Credit: "); lcd.print(montoTotal);
deteccionDeCoin = 0; //Reset del detector
}
}
In any case thank you very much for taking the time to read it and any help will be appreciated.