Ask Your Question
4

How can the LCD (I2C) display the sum of money inserted into the coin acceptor?

asked 2023-07-08 22:02:50 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-07-08 22:15:02 +0000

pufferfish gravatar image

To display the sum of money inserted into the coin acceptor on an LCD display through I2C, you will need to integrate the following steps:

  1. Initialize the coin acceptor module and the LCD display module in your program.
  2. Set up a variable to store the total amount of money inserted so far.
  3. Write a function to read the value of each coin inserted and add it to the total amount.
  4. Call this function whenever a coin is inserted.
  5. Display the updated total amount on the LCD display by writing the value of the variable to the appropriate position on the display.

Here is some sample code to help you get started:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // Initialize the LCD display module
int totalAmount = 0; // Initialize the total amount of money inserted to zero

void setup()
{
  Wire.begin(); // Initialize the I2C bus
  coinAcceptorSetup(); // Initialize the coin acceptor module
  lcd.init(); // Initialize the LCD display
  lcd.backlight(); // Turn on the backlight
}

void loop()
{
  if (coinInserted())
  {
    addCoinValueToTotal(); // Add the value of the inserted coin to the total
    showTotalAmount(); // Display the updated total on the LCD display
  }
}

void addCoinValueToTotal()
{
  // Code to read the value of the inserted coin and add it to the total
}

void showTotalAmount()
{
  lcd.setCursor(0, 0); // Set the cursor to the first line of the display
  lcd.print("Total amount: $"); // Display the label for the total amount
  lcd.print(totalAmount); // Display the actual total amount value
}

Note: This code is just a framework, and you will need to fill in the details for the coinAcceptorSetup() and coinInserted() functions according to your specific hardware and software requirements.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-08 22:02:50 +0000

Seen: 8 times

Last updated: Jul 08 '23