Hi my name is Sergio and I'm trying to make a vending machine using Arduino and a multi coin acceptor, i already have a code that works just fine with the serial monitor but i want to add a monochrome OLED display (JMD 2.42" i2c/spi - brand "smart").
For what i've read, the wire.h library and the use of interrupts at the same sketch is not possible, so i would like if there is any other option so i can display the information other that serial monitor?
i'll attach the working code without any OLED display (just the Serial.prints()
By the way, i tried an example code (ssd1306_128x64_spi)and the display works just fine.
/*--------CODIGOS DE PRODUCTOS--------------------------------------------------------------------
jpr = jabon para ropa
spr = suavizante para ropa
jpt = jabon para trastes
clr = cloro
lpp = limpiador para pisos
*///------PRECIOS DE LOS PRODUCTOS----------------------------------------------------------------
int jpr = 20;
int spr = 27;
int jpt = 37; //INTRODUCIR EL PRECIO EN PESOS MEXICANOS.............
int clr = 12;
int lpp = 23;
//--------TIEMPOS DE LLENADO----------------------------------------------------------------------
int TJPR = 3500;
int TSPR = 3000;
int TJPT = 4000; //INTRODUCIR EL TIEMPO EN MILISEGUNTOS / EJEMPLO: [5.5 seg = 5500]
int TCLR = 2000;
int TLPP = 1800;
//--------PINES DE SALIDA PARA CONTROLAR BOMBAS---------------------------------------------------
const int cambio = 11;
const int bjpr = 10;
const int bspr = 9;
const int bjpt = 6;
const int bclr = 5;
const int blpp = 3;
//--------ENTRADAS--------------------------------------------------------------------------------
int CAMBIO;
int JPR;
int SPR;
int JPT;
int CLR;
int LPP;
//------PIN DE ENTRADA DE MONEDAS-----------------------------------------------------------------
const int SignalPin = 2;
//-----NUMERO DE PULSOS POR MONEDA----------------------------------------------------------------
const int UnPeso = 1;
const int DosPesos = 2;
const int CincoPesos = 3;
const int DiezPesos = 4;
const int DiezPesos5 = 5;
//------------------------------------------------------------------------------------------------
volatile int pulso = 0;
unsigned long MillisUltPulso = 0;
//------------------------------------------------------------------------------------------------
int PulsosAcum = 0;
int CreditoAcum = 0;
int MaxTimePulse = 200;
////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
//pinMode(blpp,OUTPUT);
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(SignalPin), coinInterrupt, RISING);
delay(100);}
////////////////////////////////////////////////////////////////////////////////////////////////
void coinInterrupt(){
pulso++;
MillisUltPulso = millis();
Serial.println("Interrupcion");}
///////////////////////////////////////////////////////////////////////////////////////////////
void loop(){
int valuea0=analogRead(A0);
int valuea1=analogRead(A1);
//-----CAMBIO----------------------------------------------------------------------------------
//CAMBIO=analogRead(valuea1>-1000&&valuea1<200);
if((valuea1>-1000&&valuea1<200)&&(CreditoAcum||(0))){
while(CreditoAcum||(0)){
CreditoAcum-=1;
Serial.print("CREDITO: $");
Serial.println(CreditoAcum);
analogWrite(cambio,255);
delay (300);
analogWrite(cambio,0);
delay(300);}
Serial.print("CREDITO: $ ");
Serial.print(CreditoAcum);
Serial.println(".00");
Serial.println("¡¡GRACIAS POR SU COMPRA!!");
Serial.println("... ↓↓↓ TOME SU CAMBIO ↓↓↓ ... ");}
else {analogWrite(cambio,255);}
//-----JABON PARA ROPA-------------------------------------------------------------------------
JPR = analogRead(valuea1>200&&valuea1<630);
if((valuea1>200&&valuea1<630)&&(CreditoAcum>=(jpr))){
analogWrite(blpp,255);
Serial.println("SIRVIENDO JABON PARA ROPA...");
delay (TJPR);
CreditoAcum=CreditoAcum-(jpr);
analogWrite(bjpr,0);
Serial.print("PRODUCTO SERVIDO / CREDITO RESTANTE: $");
Serial.print(CreditoAcum);
Serial.println(".00");}
else if ((valuea1>200&&valuea1<630)&&(CreditoAcum<jpr)){
Serial.println("INTRODUSCA MAS MONEDAS");
Serial.print("CREDITO INSUFICIENTE: $");
Serial.print(CreditoAcum);
Serial.println(".00");
delay(500);}
//-----SUAVIZANTE PARA ROPA--------------------------------------------------------------------
//SPR = analogRead(valuea1>630&&valuea1< 900);
if((valuea1>630&&valuea1< 900)&&(CreditoAcum>=(spr))){
analogWrite(bspr,255);
Serial.println("SIRVIENDO SUAVIZANTE PARA ROPA...");
delay (TSPR);
CreditoAcum=CreditoAcum-(spr);
analogWrite(bspr,0);
Serial.print("PRODUCTO SERVIDO / CREDITO RESTANTE: $");
Serial.print(CreditoAcum);
Serial.println(".00");}
else if ((valuea1>630&&valuea1< 900)&&(CreditoAcum<spr)){
Serial.println("INTRODUSCA MAS MONEDAS");
Serial.print("CREDITO INSUFICIENTE: $");
Serial.print(CreditoAcum);
Serial.println(".00");
delay(500);}
//-----JABON PARA TRASTES----------------------------------------------------------------------
//JPT = analogRead(valuea1>630&&valuea1< 900);
if((valuea0>-1000&&valuea0<200)&&(CreditoAcum>=(jpt))){
analogWrite(bjpt,255);
Serial.println("SIRVIENDO JABON PARA TRASTES...");
delay (TJPT);
CreditoAcum=CreditoAcum-(jpt);
analogWrite(bjpt,0);
Serial.print("PRODUCTO SERVIDO / CREDITO RESTANTE: $");
Serial.print(CreditoAcum);
Serial.println(".00");}
else if ((valuea0>-1000&&valuea0<200)&&(CreditoAcum<jpt)){
Serial.println("INTRODUSCA MAS MONEDAS");
Serial.print("CREDITO INSUFICIENTE: $");
Serial.print(CreditoAcum);
Serial.println(".00");
delay(500);}
//-----CLORO-----------------------------------------------------------------------------------
//CLR = analogRead(valuea0>200&&valuea0<630);
if((valuea0>200&&valuea0<630)&&(CreditoAcum>=(clr))){
analogWrite(bclr,0);
Serial.println("SIRVIENDO CLORO...");
delay (TCLR);
CreditoAcum=CreditoAcum-(clr);
analogWrite(bclr,255);
Serial.print("PRODUCTO SERVIDO / CREDITO RESTANTE: $");
Serial.print(CreditoAcum);
Serial.println(".00");}
else if ((valuea0>200&&valuea0<630)&&(CreditoAcum<clr)){
Serial.println("INTRODUSCA MAS MONEDAS");
Serial.print("CREDITO INSUFICIENTE: $");
Serial.print(CreditoAcum);
Serial.println(".00");
delay(500);}
else {analogWrite(bclr,255);}
//-----LIMPIADOR PARA PISOS--------------------------------------------------------------------
//LPP = analogRead(valuea0>630&&valuea0< 900);
if((valuea0>630&&valuea0< 900)&&(CreditoAcum>=(lpp))){
analogWrite(blpp,0);
Serial.println("SIRVIENDO LIMPIADOR PAR PISOS...");
delay (TLPP);
CreditoAcum=CreditoAcum-(lpp);
analogWrite(blpp,255);
Serial.print("PRODUCTO SERVIDO / CREDITO RESTANTE: $");
Serial.print(CreditoAcum);
Serial.println(".00");}
else if ((valuea0>630&&valuea0< 900)&&(CreditoAcum<lpp)){
Serial.println("INTRODUSCA MAS MONEDAS");
Serial.print("CREDITO INSUFICIENTE: $");
Serial.print(CreditoAcum);
Serial.println(".00");
delay(500);}
else {analogWrite(blpp,255);}
//-----LOGICA DE CREDITOS----------------------------------------------------------------------
unsigned long lastTime = millis() - MillisUltPulso;
if((pulso > 0) && (lastTime >= MaxTimePulse)){
PulsosAcum = pulso;
pulso = 0;
Serial.print("Pulses: ");
Serial.print(PulsosAcum);
Serial.print(" LastTime: ");
Serial.print(lastTime);
Serial.print(" LastPulse: ");
Serial.println(MillisUltPulso);}
switch (PulsosAcum){
case UnPeso:
PulsosAcum = 0;
Serial.println("MONEDA DEPOSITADA DE $ 1.00");
CreditoAcum += 1;
Serial.print("CREDITO: $ ");
Serial.print(CreditoAcum);
Serial.println(".00");
break;
case DosPesos:
PulsosAcum = 0;
Serial.println("MONEDA DEPOSITADA DE $ 2.00");
CreditoAcum += 2;
Serial.print("CREDITO: $ ");
Serial.print(CreditoAcum);
Serial.println(".00");
break;
case CincoPesos:
PulsosAcum = 0;
Serial.println("MONEDA DEPOSITADA DE $ 5.00");
CreditoAcum += 5;
Serial.print("CREDITO: $ ");
Serial.print(CreditoAcum);
Serial.println(".00");
break;
case DiezPesos:
PulsosAcum = 0;
Serial.println("MONEDA DEPOSITADA DE $ 10.00");
CreditoAcum += 10;
Serial.print("CREDITO: $ ");
Serial.print(CreditoAcum);
Serial.println(".00");
break;
case DiezPesos5:
PulsosAcum = 0;
Serial.println("MONEDA DEPOSITADA DE $ 10.00");
CreditoAcum += 10;
Serial.print("CREDITO: $ ");
Serial.print(CreditoAcum);
Serial.println(".00");
break;}}
vending machine.ino (7.69 KB)