- //Piggy Bank code by mizzuddinkamal
- // include the library code:
- #include <LiquidCrystal.h>
- #include <Wire.h>
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- // include the library code:
- #include <LiquidCrystal.h>
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(7,8,9,10,11,12);
- volatile byte CoinPulseCount = 0;
- byte NewCoinInserted;
- byte Command = 0;
- int OpticalCountPin = 3;
- volatile unsigned long PulseTime;
- float CurrentCredit;
- float NewCurrentCredit;
- String OnePulse = "50 Sen";
- String TwoPulses = "50 Sen";
- String ThreePulses = "20 Sen";
- String FourPulses = "20 Sen";
- String FivePulses = "£1";
- String SixPulses = "£2";
- void showCredit(){
- NewCurrentCredit = (CurrentCredit/100) + NewCurrentCredit;
- Serial.print("Total Credit: RM ");
- Serial.println(NewCurrentCredit);
- lcd.begin(16,2);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Total Credit: RM");
- lcd.setCursor(0,1);
- lcd.print(NewCurrentCredit);
- }
- void setup(){
- Serial.begin(9600);
- Serial.println("Waiting...");
- Serial.println();
- pinMode(OpticalCountPin, INPUT);
- attachInterrupt(1, CoinPulse, RISING);
- lcd.setCursor(0,0);
- lcd.print("Waiting. . .");
- }
- void loop(){
- if(CoinPulseCount > 0 && millis() - PulseTime > 200){
- NewCoinInserted = CoinPulseCount;
- CoinPulseCount = 0;
- }
- switch(NewCoinInserted){
- case 1:
- Serial.println(OnePulse + " inserted");
- CurrentCredit = 50;
- showCredit();
- NewCoinInserted = 0;
- break;
- case 2:
- Serial.println(TwoPulses + " inserted");
- CurrentCredit = 50;
- showCredit();
- NewCoinInserted = 0;
- break;
- case 3:
- Serial.println(ThreePulses + " inserted");
- CurrentCredit = 20;
- showCredit();
- NewCoinInserted = 0;
- break;
- case 4:
- Serial.println(FourPulses + " inserted");
- CurrentCredit = 20;
- showCredit();
- 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();
- }
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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.