Hello,
I am new here and I have no experience with arduino. I apologize if I am posting the question incorrectly.
Here is what I need help with. I have bought a diy vending machine which someone made and it runs on arduino. It has a coin acceptor, the model is CH-926, it has one lcd screen, a microcontroler MEGA 2560, 4 relays on the relay module and 4 step motors.
Everything works fine, but the only issue is that he programmed it to count cents in the local currency. So for example if somebody puts in lets say 5 coins the machine counts as +10 cents and +10 cents and +10 cents and this takes about 10 to 20 seconds to get to the sum of 5 because 1 coin equals to 10 times 10 cents so 100 cents. Is there a way to program the arduino code so that it only counts the coins not cents, so if 1 is inserted five times it's +1 +1 +1 +1 +1. Also the machine is programed to refuse cents, it only accepts coins, but it unfortunately counts the coins as cents. Is this problem solvable?
In the local currency here we have a coin of 1, 2 and 5. The cents are irrelevant and I do not want the machine to use them or count the coins as cents. I hope you understand me.
I again apologize if I am writing my question in a wrong way and any help would be very much appreciated.
Thank you.
This is the code and I apologize if I copied the wrong thing, this code was sent to me by the man who sold me the machine, he said it's the code to change the price:
const int cijena1 = 100 ;
const int cijena2 = 100 ;
const int cijena3 = 100 ;
const int cijena4 = 100 ;
float Cijena1 = cijena1; float Cijena2 = cijena2; float Cijena3 = cijena3; float Cijena4 = cijena4; int SetUp = 0; void coinInterrupt(){ cents = cents + 1; CurrentMillis = millis ();} void setup() { pinMode (4, OUTPUT); pinMode (5, OUTPUT); pinMode (6, OUTPUT); pinMode (7, OUTPUT); digitalWrite (4, HIGH); digitalWrite (5, HIGH); digitalWrite (6, HIGH); digitalWrite (7, HIGH); pinMode (8, INPUT); pinMode (9, INPUT); pinMode (10, INPUT); pinMode (11, INPUT); pinMode (12, INPUT); SetUp = digitalRead (12); delay(1); stepper1.setMaxSpeed(2000.0); stepper1.move(1); stepper1.move(-1); stepper1.setSpeed(stepperSpeed); stepper1.setCurrentPosition (0); stepper2.setMaxSpeed(2000.0); stepper2.move(1); stepper2.move(-1); stepper2.setSpeed(stepperSpeed); stepper2.setCurrentPosition (0); stepper3.setMaxSpeed(2000.0); stepper3.move(1); stepper3.move(-1); stepper3.setSpeed(stepperSpeed); stepper3.setCurrentPosition (0); stepper4.setMaxSpeed(2000.0); stepper4.move(1); stepper4.move(-1); stepper4.setSpeed(stepperSpeed); stepper4.setCurrentPosition (0); attachInterrupt(digitalPinToInterrupt(2), coinInterrupt, RISING); lcd.begin(); lcd.backlight (); }
void loop() { kredit = cents ; Kredit = cents ; if (SetUp == HIGH) { pb1 = digitalRead(8); pb2 = digitalRead(9); pb3 = digitalRead(10); pb4 = digitalRead(11); if (pb1 == LOW && pb2 == LOW && pb3 == LOW && pb4 == LOW) { lcd.setCursor(0,0); lcd.print(" CONDOMISMA "); lcd.setCursor(0,1); lcd.print(" SetUp mode "); digitalWrite (4, HIGH); digitalWrite (5, HIGH); digitalWrite (6, HIGH); digitalWrite (7, HIGH); } else if (pb1 == HIGH && pb2 == LOW && pb3 == LOW && pb4 == LOW) { digitalWrite (4, LOW); stepper1.move(5000); stepper1.setSpeed(700); stepper1.run();} else if (pb2 == HIGH && pb1 == LOW && pb3 == LOW && pb4 == LOW) { digitalWrite (5, LOW); stepper2.move(5000); stepper2.setSpeed(700); stepper2.run(); } else if (pb3 == HIGH && pb2 == LOW && pb1 == LOW && pb4 == LOW) { digitalWrite (6, LOW); stepper3.move(5000); stepper3.setSpeed(700); stepper3.run(); } else if (pb4 == HIGH && pb2 == LOW && pb3 == LOW && pb1 == LOW) { digitalWrite (7, LOW); stepper4.move(5000); stepper4.setSpeed(700); stepper4.run(); } } else if (SetUp == LOW) { if (pb1 == LOW && pb2 == LOW && pb3 == LOW && pb4 == LOW){ if (cents > 0) { lcd.setCursor(0,0); lcd.print(" "); lcd.setCursor(1,1); lcd.print("Kredit="); lcd.print (Kredit/10); lcd.print("KM");} if (cents <= 0) { lcd.setCursor(0,0); lcd.print(" SUVENIRI "); lcd.setCursor(0,1); lcd.print(" SOUVENIRS ");}} /* 1 */ if (stepper1.distanceToGo() == 0) {pb1 = digitalRead(8);} if (pb1 == HIGH && pb2 == LOW && pb3 == LOW && pb4 == LOW && kredit >= cijena1) { digitalWrite (4, LOW); buttonState1 = HIGH; CurrentMillis = millis ();} if (buttonState1 == HIGH ) { stepper1.moveTo(4103); stepper1.setSpeed(stepperSpeed); stepper1.runSpeedToPosition(); if (stepper1.distanceToGo() == 0) { stepper1.setCurrentPosition (0); cents = cents - cijena1; delay (300); digitalWrite (4, HIGH); buttonState1 = LOW; lcd.setCursor(0,0); lcd.print(" Hvala! "); lcd.setCursor(1,1); lcd.print("Vidimo se opet "); delay (3000); }} else if (pb1 == HIGH && pb2 == LOW && pb3 == LOW && pb4 == LOW && kredit < cijena1) { lcd.setCursor(0,0); lcd.print(" "); lcd.print (Cijena1/10); lcd.print (""); lcd.setCursor(1,1); lcd.print("Kredit="); lcd.print (Kredit/10); lcd.print("KM "); delay (2000);} /* 4 */ if (stepper4.distanceToGo() == 0) { pb4 = digitalRead(11);} if (pb4 == HIGH && pb2 == LOW && pb3 == LOW && pb1 == LOW && kredit >= cijena4) { digitalWrite (7, LOW); buttonState4 = HIGH; CurrentMillis = millis ();} if (buttonState4 == HIGH) { stepper4.moveTo(4103); stepper4.setSpeed(stepperSpeed); stepper4.runSpeedToPosition(); if (stepper4.distanceToGo() == 0) { stepper4.setCurrentPosition (0); cents = cents - cijena4; delay (300); digitalWrite (7, HIGH); buttonState4 = LOW; lcd.setCursor(0,0); lcd.print(" Hvala! ");lcd.setCursor(1,1); lcd.print("Vidimo se opet "); delay (3000);}} else if (pb1 == LOW && pb2 == LOW && pb3 == LOW && pb4 == HIGH && kredit < cijena4) { lcd.setCursor(0,0); lcd.print(" "); lcd.print (Cijena4/10); lcd.print (""); lcd.setCursor(1,1); lcd.print("Kredit="); lcd.print (Kredit/10); lcd.print("KM "); delay (2000);} /*2*/ if (stepper2.distanceToGo() == 0) { pb2 = digitalRead(9);} if (pb2 == HIGH && pb1 == LOW && pb3 == LOW && pb4 == LOW && kredit >= cijena2) { digitalWrite (5, LOW); buttonState2 = HIGH; CurrentMillis = millis ();} if (buttonState2 == HIGH) { stepper2.moveTo(4103); stepper2.setSpeed(stepperSpeed); stepper2.runSpeedToPosition(); if (stepper2.distanceToGo() == 0) { stepper2.setCurrentPosition (0); cents = cents - cijena2; delay (300); digitalWrite (5, HIGH); buttonState2 = LOW; lcd.setCursor(0,0); lcd.print(" Hvala! "); lcd.setCursor(1,1); lcd.print("Vidimo se opet "); delay (3000);}} else if (pb1 == LOW && pb2 == HIGH && pb3 == LOW && pb4 == LOW && kredit < cijena2) { lcd.setCursor(0,0); lcd.print(" "); lcd.print (Cijena2/10); lcd.print (""); lcd.setCursor(1,1); lcd.print("Kredit="); lcd.print (Kredit/10); lcd.print("KM "); delay (2000);} /* 3 */ if (stepper3.distanceToGo() == 0) { pb3 = digitalRead(10);} if (pb3 == HIGH && pb2 == LOW && pb1 == LOW && pb4 == LOW && kredit >= cijena3) { digitalWrite (6, LOW); buttonState3 = HIGH; CurrentMillis = millis ();} if (buttonState3 == HIGH) { stepper3.moveTo(4103); stepper3.setSpeed(stepperSpeed); stepper3.runSpeedToPosition(); if (stepper3.distanceToGo() == 0) { stepper3.setCurrentPosition (0); cents = cents - cijena3; delay (300); digitalWrite (6, HIGH); buttonState3 = LOW; lcd.setCursor(0,0); lcd.print(" Hvala! "); lcd.setCursor(1,1); lcd.print("Vidimo se opet "); delay (3000);}} else if (pb1 == LOW && pb2 == LOW && pb3 == HIGH && pb4 == LOW && kredit < cijena3) { lcd.setCursor(0,0); lcd.print(" "); lcd.print (Cijena3/10); lcd.print (""); lcd.setCursor(1,1); lcd.print("Kredit="); lcd.print (Kredit/10); lcd.print("KM "); delay (2000);} } if (pb3 == HIGH || pb2 == HIGH || pb1 == HIGH || pb4 == HIGH) { CurrentMillis = millis ();} if (millis () - CurrentMillis >= 300000UL) {cents = 0; CurrentMillis = millis ();} }