Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int pisoQty = 0;
- int limaQty = 0;
- int sampuQty = 0;
- int pisoTotal = 0;
- int limaTotal = 0;
- int sampuTotal = 0;
- int grandTotal = 0;
- //Coin Acceptor
- Servo servoSorter;
- const int coinInt = 0;
- volatile int coinsValue = 0;
- int coinsChange = 0;
- int coinCurrentTotal = 0;
- int coinAcceptor = 0;
- void setup() {
- //Coin Acceptor
- pinMode(2, INPUT_PULLUP);
- Serial.begin(9600);
- attachInterrupt(coinInt, coinInserted, RISING);
- //Hardware is now ready
- Serial.println("Ready...");
- }
- void coinInserted()
- {
- coinsChange = 1;
- coinsValue = coinsValue + 1;
- }
- void loop() {
- if (coinsChange == 1)
- {
- if (coinsValue == 10) {
- coinsChange = 0;
- sampuQty++;
- sampuTotal += 10;
- grandTotal += 10;
- //Serial.println("You deposit " + String(coinsValue));
- Serial.println(String(coinsValue));
- coinCurrentTotal = 0;
- coinsValue = 0;
- } else if (coinsValue == 5) {
- coinsChange = 0;
- limaQty++;
- limaTotal += 5;
- grandTotal += 5;
- //Serial.println("You deposit " + String(coinsValue));
- Serial.println(String(coinsValue));
- coinCurrentTotal = 0;
- coinsValue = 0;
- } else if (coinsValue == 1) {
- coinsChange = 0;
- pisoQty++;
- pisoTotal++;
- grandTotal++;
- //Serial.println("You deposit " + String(coinsValue));
- Serial.println(String(coinsValue));
- coinCurrentTotal = 0;
- coinsValue = 0;
- } else if (coinsValue > 10) {
- coinsChange = 0;
- coinCurrentTotal = 0;
- coinsValue = 0;
- }
- }
- //Check if coin acceptor is now exiting
- if (Serial.available() > 0) {
- String coinAcceptorString = Serial.readString();
- coinAcceptor = coinAcceptorString.toInt();
- //If coinAcceptor is equal to 100 then exit
- if (coinAcceptor == 100) {
- isTrue = false;
- choice = 0;
- coinAcceptor = 0;
- detachInterrupt(digitalPinToInterrupt(2));
- //Serial.println("Coin Acceptor has been closed.");
- servoSorter.detach();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement