naivxnaivet

CoinSlotSolenoid

Jan 30th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #define coinSlotPin 2
  2. #define coinsValue = coins
  3. #define solenoidPin 3
  4. #define ledPinRed 4
  5. #define ledPinGreen 5
  6.  
  7. volatile int coins = -1;
  8. int lastCoinCount = 0;
  9.  
  10.  
  11.  
  12. byte delayTime = 5;
  13. int timeDelay = 1000 * delayTime;
  14.  
  15. void setup() {
  16. // Open serial communications and wait for port to open:
  17. pinMode(ledPinRed, OUTPUT);
  18. pinMode(ledPinGreen, OUTPUT);
  19. pinMode(solenoidPin, OUTPUT);
  20. digitalWrite(solenoidPin, LOW);
  21. Serial.begin(9600);
  22.  
  23. digitalWrite(ledPinRed, LOW);
  24. digitalWrite(ledPinGreen, HIGH);
  25. pinMode(coinSlotPin, INPUT_PULLUP);
  26. attachInterrupt(digitalPinToInterrupt(coinSlotPin), coinInserted, FALLING);
  27. coins = 0;
  28.  
  29. }
  30.  
  31. void loop() {
  32. Serial.println(coins);
  33.  
  34. if (coins >= 1) //dito papalitan yung coins na need
  35. {
  36. digitalWrite(ledPinRed, HIGH);
  37. digitalWrite(ledPinGreen, LOW);
  38. digitalWrite(solenoidPin, HIGH);
  39. delay(timeDelay);
  40. digitalWrite(ledPinGreen, HIGH);
  41. digitalWrite(ledPinRed, LOW);
  42. digitalWrite(solenoidPin, LOW);
  43. coins = 0;
  44. }
  45. }
  46.  
  47. void coinInserted() {
  48. coins++;
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment