Dear friends,
Can anyone help me with this?
I am using an Arduino UNO. I am using interrupts. My program is working well when I use INT0, but I just change the pin number and the results are quite different, thousands of pulses are received, contrary when I use pint 2(INT0). Is there any difference in HW inside the chip?.
This is my program.
=====
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
const int InterruptPin = 3; // Interrupcion One(0) pin 3 Arduino UNO
int contador=0; //Contador de pulsos
int Anterior = contador; //Antes int
byte Monedas=0; // Numero de Billetes depositados
double Precio=0; //Total Dinero ingresado con 2 decimales
int Duracion=0; // Duracion del pulso negativo
LiquidCrystal_I2C lcd(0x3f,20,4); // Direccion 0x3f obtenido por scaner
void setup(){
//RUTINAA CONFIGURACION DEL DISPLAY//
lcd.init();
lcd.begin(20,4); // initialize the lcd.
lcd.setBacklight(HIGH);
lcd.setBacklight(HIGH);
lcd.home();
delay(250);
lcd.print("AGUAS AMAZONAS CORP.");
delay(500);
delay(500);
lcd.setCursor(0,1);
delay(1000);
lcd.print("WATER VENDING");
delay(1000);
lcd.setCursor(0,2);
delay(1000);
lcd.print("Copy Right...");
delay(1000);
delay(1000);
lcd.setCursor(0,3);
delay(1000);
lcd.print("AGUA FRESCA SIEMPRE.");
delay(100);
//RUTINE INTERRUPT 1
digitalWrite(InterruptPin, HIGH); //NEW FOR NOISE SUPRESSION ENABLE PULL UP
pinMode(InterruptPin, INPUT);
attachInterrupt(digitalPinToInterrupt(InterruptPin), CoinAcceptor, FALLING);
// Por flaco de bajada
interrupts(); //adicionada por OmarE
}
void loop(){
Duracion=pulseIn(InterruptPin,LOW); // Mide duracion del pulso en microsegundos
if(Anterior!=contador){
Display1(); // Muestra mensajes
Anterior=contador; // Almacena el ultimo pulso
}
if (Anterior=contador){
switch (contador){
case 1:
//Precio+=1000; //Billete de 1000
Monedas++;
Display();
contador=0;
break;
case 2:
//Precio+=2000; //Billete de 2mil
Monedas++;
Display();
contador=0;
break;
case 5:
//Precio+=5000; //Billete de 5mil pesos nueva
Monedas++;
Display();
contador=0;
break;
case 10:
//Precio+=10000; //Billete de 10mil
Monedas++;
Display();
contador=0;
break;
case 20:
//Precio+=20000; //Billete de 20mil
Monedas++;
Display();
contador=0;
break;
default:
Monedas++;
Display();
contador=0;
break;
}
}
}
void CoinAcceptor(){
contador++;
Precio+=1000;
}
void Display(){
lcd.setCursor(0,2);
lcd.print("MONEDAS: ");
lcd.setCursor(8,2); //Posicion # Monedas
lcd.print(Monedas); // AL DECLARARLO BYTE NO HUBO NECESIDAD
lcd.setCursor(12,2); //Posicion Duracion pulso.
lcd.print(Duracion); //Escribe Duracion pulso
lcd.setCursor(0,3); //Posicion PRECIO
lcd.print("VALOR:$ ");
lcd.setCursor(7,3); //Posicion PRECIO
lcd.print(Precio); // AL DECLARARLO BYTE NO HUBO NECESIDAD
lcd.setCursor(18,3); //Posicion Pulso
lcd.print(contador); // AL DECLARARLO BYTE NO HUBO NECESIDAD
}
void Display1(){
lcd.setCursor(0,0);
lcd.print("GRACIAS POR ELEGIR..");
lcd.setCursor(0,1); //Posicion # Monedas
lcd.print("PROCESANDO..."); // AL DECLARARLO BYTE NO HUBO NECESIDA
delay(500);
//lcd.clear();
}