#include <LiquidCrystal.h>
// Define pin numbers
const int coin10Pin = 2; // Pin for 10 cent coin
const int coin20Pin = 3; // Pin for 20 cent coin
const int coin50Pin = 4; // Pin for 50 cent coin
const int buzzerPin = 5; // Pin for buzzer
const int resetButtonPin = 6; // Pin for reset button
// Create LCD object
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // Adjust pins according to your setup
// Variables to keep track of total amount
float totalAmount = 0.0;
}
void setup()
{
// Set pin modes
pinMode(coin10Pin, INPUT_PULLUP);
pinMode(coin20Pin, INPUT_PULLUP);
pinMode(coin50Pin, INPUT_PULLUP);
pinMode(buzzerPin, OUTPUT);
pinMode(resetButtonPin, INPUT_PULLUP);
// Initialize LCD
lcd.begin(16, 2);
lcd.print("Jumlah: RM 0.00");
}
void loop() {
// Check for coins
checkCoin(coin10Pin, 0.10);
checkCoin(coin20Pin, 0.20);
checkCoin(coin50Pin, 0.50);
// Check for reset button
if (digitalRead(resetButtonPin) == LOW) {
resetCounter();
}
// Small delay to prevent bouncing
delay(100);
}
void checkCoin(int pin, float value) {
static unsigned long lastPressTime = 0; // For debounce
if (digitalRead(pin) == LOW) {
unsigned long currentTime = millis();
if (currentTime - lastPressTime >= 200) { // Debounce time
totalAmount += value;
lcd.clear();
lcd.print("Jumlah: RM ");
lcd.print(totalAmount, 2); // Display amount with 2 decimal places
tone(buzzerPin, 1000, 200); // Sound buzzer
lastPressTime = currentTime; // Update last press time
}
}
}
void resetCounter() {
totalAmount = 0.0;
lcd.clear();
lcd.print("Jumlah: RM 0.00");
}
- Questioners know what their hardware and software looks like but the volunteers here do not. You need to fully explain what’s not working, and how it is supposed to work.
- Before asking your questions, please read all the posting guidelines, follow these guidelines when you post your questions.
Hardware
- As always, show us a good schematic of your proposed circuit. Hand drawn schematics are acceptable.
- Schematic diagrams are the universal language of electronics
- We use schematics to communicate hardware design.
- Show us several good image views of your actual wiring.
- Give WEB links to your major components.
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Uno"
6:22:14: error: expected initializer before '}' token
void setup()}
^
6:22:14: error: expected declaration before '}' token
exit status 1
expected initializer before '}' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
- Get rid of the }
if (digitalRead(pin) == LOW) {
unsigned long currentTime = millis();
if (currentTime - lastPressTime >= 200) { // Debounce time
totalAmount += value;
lcd.clear();
lcd.print("Jumlah: RM ");
lcd.print(totalAmount, 2); // Display amount with 2 decimal places
tone(buzzerPin, 1000, 200); // Sound buzzer
lastPressTime = currentTime; // Update last press time
}
}
}
void resetCounter() {
totalAmount = 0.0;
lcd.clear();
lcd.print("Jumlah: RM 0.00");
}
the last coding error
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Uno"
C:\Users\user\OneDrive\Documents\Arduino\6\6.ino: In function 'void loop()':
6:23:14: error: a function-definition is not allowed here before '{' token
void setup() {
^
6:36:13: error: a function-definition is not allowed here before '{' token
void loop() {
^
6:51:38: error: a function-definition is not allowed here before '{' token
void checkCoin(int pin, float value) {
^
6:67:21: error: a function-definition is not allowed here before '{' token
void resetCounter() {
^
exit status 1
a function-definition is not allowed here before '{' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
did you remove the correct brace?
Post #1 code seemed mostly correct, however as already noted, your #3 post has curly brace back to front at end of setup() ....it is highlighted so you should be able to see that clearly enough surely.
This Topic has been locked as it is the identical or too similar your other topic.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
Thank you.