Hello everyone, I'm new to Arduino and I'm trying to make a piggy bank that tells me the total amount. I have a Pyramid 5600 Bill acceptor connected to my Arduino with a display. I was able to figure the code for displaying each bill amount on the lcd. the problem is, I'm having trouble figuring out how to add the total amount. for example I add $1 to the acceptor and the display shows $1 and when I add a 5$ bill the lcd changes to $5 instead of displaying a total of $6. I know it's probably very simple but I can't figure it out even after looking at other similar sketches and vids. and please dumb it down as much as you can because I'm still very new to this and still trying to learn. and sorry in advance if I don't post the code correctly. I posted a simalar post on here a week ago and people told me I posted it wrong
//pulse mode, 2 pulses per dollar
//pyramid apex 5600 bill acceptor
//red 12v, black & violet gnd, brown to digital 2
#include <LiquidCrystal_I2C.h>
#define BILL 2
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.clear();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Total Balance:");
pinMode(BILL, INPUT);
digitalWrite(BILL, HIGH);
}
void loop() {
lcd.setCursor(1, 1);
while (digitalRead(BILL) == HIGH)
;
int counter = 1;
long start = millis();
int lastRead = LOW;
long lastChange = start;
while (millis() - lastChange < 60) {
delay(25);
if (lastRead != digitalRead(BILL)) {
counter++;
lastChange = millis();
}
lastRead = digitalRead(BILL);
}
if (counter > 1) {
lcd.print("$");
int approximateDollars = counter / 4;
if (approximateDollars > 0 && approximateDollars <= 2)
lcd.print(1);
else if (approximateDollars > 2 && approximateDollars <= 6)
lcd.print(5);
else if (approximateDollars > 6 && approximateDollars <= 12)
lcd.print(1);
else if (approximateDollars > 12 && approximateDollars <= 30)
lcd.print(20);
else if (approximateDollars > 30 && approximateDollars <= 60)
lcd.print(5);
else if (approximateDollars > 60 && approximateDollars <= 120)
lcd.print(10);
else if (approximateDollars > 120 && approximateDollars <= 240)
lcd.print(20);
else if (approximateDollars > 240 && approximateDollars <= 480)
lcd.print(50);
Serial.println(".00 detected");
}
}
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
You're going the wrong way into programming. Get a basic course in C, or C## and learn. Details are often delicate and copying code, without understanding the details, is like jumping into the dark.
I know, I'm trying to study everything but with work I barely have free time and the little time I do have, I just want to get a project going. I'm actually learning a lot through other peoples codes and youtube vids but yes you are correct I need to go about it the right way
If you're limited on time then doing it the slow and hard way doesn't make much sense.
I know the "right" way sounds like something you don't have time for, but it's actually something you don't have time to be without. Those videos make it look easy don't they? How long will it take before you understand that trying to copy something you don't understand is the longer road?
This Forum is no help at all. If everyone had time to take classes we wouldn't need a Forum in the first place. Yes I need to learn program properly and do watch courses when I can but I don't spend too much time programming. I like to build things and every now and then i need an Arduino to run something I'm building. in this case I'm trying to make something to help me save money and yes I need the Arduino to run it And yes Knowing everything about programing would help and be a lot faster but I don't see the point in spending weeks learning everything about programing just to add a total especially now when I'm this close to it working. I figured the rest out on my own and I guess I'll figure this out on my own. thanks anyway
No, it's just not what you wanted. You want to get somewhere without having to put in the effort to get there and it seems you expect people here to put that effort in for you.
For people who are trying to learn this place works great. But we aren't here to serve you with free code since you don't have the time. I have other things to do too.
So you'd rather spend months? You say yourself you know it would be faster but you think you'll save time doing it the slow way? That makes as much sense as screen doors on a submarine.
Yes, like so many others you've hit the limit of what you can do by copying. That's nobody being mean to you. Get over yourself. That's just the way things work in the world.
Please try to keep in mind that nobody here owes you anything. We're just hobbyists trying to help other hobbyists. If you don't want to be a part of that then fine, but don't act like we owed you something.
No I wasn't asking you to do work for me I was asking for advice on how to do it.
You know, asking questions like everyone else on here. only difference is, they got help and good advice and I got keyboard warriors telling me to go take classes and figure it out myself. just like the last post. I don't see the difference in my posts compared to others so I don't seen how I get the negative feedback. I learn by watching and asking questions. Not by sitting through long courses that mostly have nothing to do with what I'm trying to do. My project mostly works from the hard work i put in already other than not adding total. I figured out counting pulses from the bill acceptor and learned as I went. I simply asked for advice on it. I didn't say "hey write my code for me" It just blows my mind. When kids ask ya'll a question do you say "go read a book and figure it out yourself"?
@southatlantagaragedoor ,
I usually stay away from programming questions because I'm not very good at reading other people's code, but here goes with questions intended to help you without just doing it for you.
In your code which variable do you think keeps a running total?
Do you know what 'scope' means?
Do you know what 'static' means?
The answers to those questions will take you closer to a solution, so I suggest you consider them in your search for a solution.
Thank you for the response. and no I wasn't expecting anyone to write a code for me I was just looking for how to. I don't mind researching and figuring it out, I just wanted a starting point and this helps a lot because it gives me a starting point
Had you followed the advice in post #3 it would have taken maybe ten or twenty minutes to get to the point of knowing how to create a variable and add a value to it. It is going to literally be the first or second lesson in just about any course you look at.
This really isn't hard.
I hope you'll take some time to take a look at some of the other posts that get the type of responses you're looking for. See how they handle the advice they do receive and how they talk to the people giving it. Compare that to your approach and put yourself in our shoes.
We're just hobbyists helping other hobbyists. We get to be choosy. That's our prerogative. You need to think less about what you think we owe you and more about how to be worth choosing.
I was able to get it working correctly by using A coin acceptor sketch and changing some things around. And the Bill acceptor can be programed to whatever pulse you choose. I had to set it to 1 pulse per dollar and set the pulse speed to slow.
Thank you for the positive response
I used a similar one but thank you. I was able to Get it working properly. and if anyone is interested in the code or has had the same problem I can post the code to help you out.