SHARE
TWEET

Untitled

a guest May 21st, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Keypad.h>
  2. #include <ShiftedLCD.h>
  3. #include <SPI.h>
  4.  
  5. //Define LCD Pin
  6. LiquidCrystal lcd(10);
  7.  
  8.  
  9. void writeLCD(int column, int row, String text, bool wait, double balance)
  10. {
  11.   // reset LCD
  12.   lcd.clear();
  13.  
  14.   // set top row with balance tracking
  15.   lcd.setCursor(0, 0);
  16.   lcd.print("Balance: ");
  17.  
  18.   // print updated balance
  19.   lcd.setCursor(10, 0);
  20.   lcd.print(balance);
  21.  
  22.   // set bottom row with params
  23.   lcd.setCursor(column, row);
  24.   lcd.print(text);
  25.   if (wait)
  26.   {
  27.     delay(2000);
  28.   }
  29. }
  30.  
  31.  
  32. int checkPosition(String codeStr)
  33. {
  34.   // if first or 2nd position are x, they are empty so can have a value inserted
  35.   if (codeStr[0] == 'x')
  36.     return 0;  
  37.   else if (codeStr[1] == 'x')
  38.     return 1;  
  39.   else
  40.   // otherwise return 666 to signify full code selection
  41.     return 666;
  42. }
  43.  
  44.  
  45.  
  46. String calculate(double balance, double cost)
  47. {
  48.   Serial.println(balance);
  49.   Serial.println(cost);
  50.   // check balance is greater than or equal to the cost of the item
  51.   if (balance >= cost or balance * 1.0001 > cost)
  52.   {
  53.     // calculate new balance
  54.     double newBal = balance - cost;
  55.     Serial.println("balance greater");
  56.     return String(newBal);
  57.   }
  58.   else if (balance == cost)
  59.   {
  60.     Serial.println("equal");
  61.     return "Balance too low";
  62.   }
  63.   else if (balance <= cost)
  64.   {
  65.     Serial.println("balance is less");
  66.     return "Balance too low";
  67.   }
  68. }
  69.  
  70. void clearSelection(String code, double balance)
  71. {
  72.   code = "xx\0";
  73.   Serial.println("Selection cleared.");
  74.  
  75.   // reset lcd
  76.   writeLCD(0, 1, "Your choice:", false, balance);
  77. }
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