Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. int pisoQty = 0;
  2. int limaQty = 0;
  3. int sampuQty = 0;
  4. int pisoTotal = 0;
  5. int limaTotal = 0;
  6. int sampuTotal = 0;
  7. int grandTotal = 0;
  8.  
  9. //Coin Acceptor
  10. Servo servoSorter;
  11. const int coinInt = 0;
  12. volatile int coinsValue = 0;
  13. int coinsChange = 0;
  14. int coinCurrentTotal = 0;
  15. int coinAcceptor = 0;
  16.  
  17. void setup() {
  18. //Coin Acceptor
  19. pinMode(2, INPUT_PULLUP);
  20. Serial.begin(9600);
  21. attachInterrupt(coinInt, coinInserted, RISING);
  22. //Hardware is now ready
  23. Serial.println("Ready...");
  24. }
  25.  
  26.  
  27. void coinInserted()
  28. {
  29. coinsChange = 1;
  30. coinsValue = coinsValue + 1;
  31. }
  32.  
  33. void loop() {
  34.  
  35. if (coinsChange == 1)
  36. {
  37. if (coinsValue == 10) {
  38. coinsChange = 0;
  39. sampuQty++;
  40. sampuTotal += 10;
  41. grandTotal += 10;
  42. //Serial.println("You deposit " + String(coinsValue));
  43. Serial.println(String(coinsValue));
  44. coinCurrentTotal = 0;
  45. coinsValue = 0;
  46. } else if (coinsValue == 5) {
  47. coinsChange = 0;
  48. limaQty++;
  49. limaTotal += 5;
  50. grandTotal += 5;
  51. //Serial.println("You deposit " + String(coinsValue));
  52. Serial.println(String(coinsValue));
  53. coinCurrentTotal = 0;
  54. coinsValue = 0;
  55. } else if (coinsValue == 1) {
  56. coinsChange = 0;
  57. pisoQty++;
  58. pisoTotal++;
  59. grandTotal++;
  60. //Serial.println("You deposit " + String(coinsValue));
  61. Serial.println(String(coinsValue));
  62. coinCurrentTotal = 0;
  63. coinsValue = 0;
  64. } else if (coinsValue > 10) {
  65. coinsChange = 0;
  66. coinCurrentTotal = 0;
  67. coinsValue = 0;
  68. }
  69. }
  70.  
  71. //Check if coin acceptor is now exiting
  72. if (Serial.available() > 0) {
  73. String coinAcceptorString = Serial.readString();
  74. coinAcceptor = coinAcceptorString.toInt();
  75. //If coinAcceptor is equal to 100 then exit
  76. if (coinAcceptor == 100) {
  77. isTrue = false;
  78. choice = 0;
  79. coinAcceptor = 0;
  80. detachInterrupt(digitalPinToInterrupt(2));
  81. //Serial.println("Coin Acceptor has been closed.");
  82. servoSorter.detach();
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement