Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Keypad.h>
- #include <ShiftedLCD.h>
- #include <SPI.h>
- //Define LCD Pin
- LiquidCrystal lcd(10);
- void writeLCD(int column, int row, String text, bool wait, double balance)
- {
- // reset LCD
- lcd.clear();
- // set top row with balance tracking
- lcd.setCursor(0, 0);
- lcd.print("Balance: ");
- // print updated balance
- lcd.setCursor(10, 0);
- lcd.print(balance);
- // set bottom row with params
- lcd.setCursor(column, row);
- lcd.print(text);
- if (wait)
- {
- delay(2000);
- }
- }
- int checkPosition(String codeStr)
- {
- // if first or 2nd position are x, they are empty so can have a value inserted
- if (codeStr[0] == 'x')
- return 0;
- else if (codeStr[1] == 'x')
- return 1;
- else
- // otherwise return 666 to signify full code selection
- return 666;
- }
- String calculate(double balance, double cost)
- {
- Serial.println(balance);
- Serial.println(cost);
- // check balance is greater than or equal to the cost of the item
- if (balance >= cost or balance * 1.0001 > cost)
- {
- // calculate new balance
- double newBal = balance - cost;
- Serial.println("balance greater");
- return String(newBal);
- }
- else if (balance == cost)
- {
- Serial.println("equal");
- return "Balance too low";
- }
- else if (balance <= cost)
- {
- Serial.println("balance is less");
- return "Balance too low";
- }
- }
- void clearSelection(String code, double balance)
- {
- code = "xx\0";
- Serial.println("Selection cleared.");
- // reset lcd
- writeLCD(0, 1, "Your choice:", false, balance);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement