SHARE
TWEET

Coin Identifier by Craynerd

redm0n Aug 15th, 2015 1,440 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Coin Identifier by craynerd
  2. //Reference: https://www.youtube.com/watch?v=f4GhBp9PUfY
  3.  
  4. volatile byte CoinPulseCount = 0;
  5. byte NewCoinInserted;
  6. byte Command = 0;
  7. int OpticalCountPin = 3;
  8. volatile unsigned long PulseTime;
  9.  
  10. String OnePulse = "5p";
  11. String TwoPulses = "10p";
  12. String ThreePulses = "20p";
  13. String FourPulses = "50p";
  14. String FivePulses = "£1";
  15. String SixPulses = "£2";
  16.  
  17. void setup(){
  18.         Serial.begin(9600);
  19.         Serial.println("Waiting...");
  20.         Serial.println();
  21.         pinMode(OpticalCountPin, INPUT);
  22.         attachInterrupt(1, CoinPulse, RISING);
  23. }
  24.  
  25. void loop(){
  26.         if(CoinPulseCount > 0 && millis() - PulseTime > 200){
  27.                 NewCoinInserted = CoinPulseCount;
  28.                 CoinPulseCount = 0;
  29.         }
  30.         switch(NewCoinInserted){
  31.                 case 1:
  32.                         Serial.println(OnePulse + " inserted");
  33.                         NewCoinInserted = 0;
  34.                         break;
  35.                 case 2:
  36.                         Serial.println(TwoPulses + " inserted");
  37.                         NewCoinInserted = 0;
  38.                         break;
  39.                 case 3:
  40.                         Serial.println(ThreePulses + " inserted");
  41.                         NewCoinInserted = 0;
  42.                         break;
  43.                 case 4:
  44.                         Serial.println(FourPulses + " inserted");
  45.                         NewCoinInserted = 0;
  46.                         break;
  47.                 case 5:
  48.                         Serial.println(FivePulses + " inserted");
  49.                         NewCoinInserted = 0;
  50.                         break;
  51.                 case 6:
  52.                         Serial.println(SixPulses + " inserted");
  53.                         NewCoinInserted = 0;
  54.                         break;
  55.         }
  56. }
  57.  
  58. void CoinPulse(){
  59.         CoinPulseCount ++;
  60.         PulseTime = millis();
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top