Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Coin Identifier by craynerd
- //Reference: https://www.youtube.com/watch?v=f4GhBp9PUfY
- volatile byte CoinPulseCount = 0;
- byte NewCoinInserted;
- byte Command = 0;
- int OpticalCountPin = 3;
- volatile unsigned long PulseTime;
- String OnePulse = "5p";
- String TwoPulses = "10p";
- String ThreePulses = "20p";
- String FourPulses = "50p";
- String FivePulses = "£1";
- String SixPulses = "£2";
- void setup(){
- Serial.begin(9600);
- Serial.println("Waiting...");
- Serial.println();
- pinMode(OpticalCountPin, INPUT);
- attachInterrupt(1, CoinPulse, RISING);
- }
- void loop(){
- if(CoinPulseCount > 0 && millis() - PulseTime > 200){
- NewCoinInserted = CoinPulseCount;
- CoinPulseCount = 0;
- }
- switch(NewCoinInserted){
- case 1:
- Serial.println(OnePulse + " inserted");
- NewCoinInserted = 0;
- break;
- case 2:
- Serial.println(TwoPulses + " inserted");
- NewCoinInserted = 0;
- break;
- case 3:
- Serial.println(ThreePulses + " inserted");
- NewCoinInserted = 0;
- break;
- case 4:
- Serial.println(FourPulses + " inserted");
- NewCoinInserted = 0;
- break;
- case 5:
- Serial.println(FivePulses + " inserted");
- NewCoinInserted = 0;
- break;
- case 6:
- Serial.println(SixPulses + " inserted");
- NewCoinInserted = 0;
- break;
- }
- }
- void CoinPulse(){
- CoinPulseCount ++;
- PulseTime = millis();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement