4 coin piggy bank

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Pugsly
 
Posts: 3
Joined: Thu Feb 28, 2013 11:32 pm

4 coin piggy bank

Post by Pugsly »

Extreme noob here. I looked all over google and this forum.

Coding isn't my strong suit at all. In reference to the 1 coin piggy bank, how does the code change or differ when going to the 4 coin version? The original only assumes a single pulse for a single coin type. With the 4 pulses how is that taken into the equation?

On the same note, how do you adjust the code to accommodate the total sum of the coins?

I hope someone can help.....

Extreme thank you's in advance

Pugsly

User avatar
adafruit_support_bill
 
Posts: 88137
Joined: Sat Feb 07, 2009 10:11 am

Re: 4 coin piggy bank

Post by adafruit_support_bill »

There is a blog-post here with a link to the code : https://www.adafruit.com/blog/2012/04/2 ... in-action/

Pugsly
 
Posts: 3
Joined: Thu Feb 28, 2013 11:32 pm

Re: 4 coin piggy bank

Post by Pugsly »

I saw that, i got that code, but i want to replicate the piggy bank with the lcd display, but using the 4 coin acceptor.


I'm assuming some part of that code will insert after the pulse length.
what i'm having trouble with is how to assume 1, 2, 3, or 4 pulses and than the display showing various amounts to be added. The current code assumes equal values of 25.


Coin values:
1 = .01 (penny)
2 = .05 (nickel)
3 = .1 (dime)
4 = .25 (quarter)
*/

const byte coinValues[4] = {
.01, .05, .1, .25}; //Coin values goes into this array


Where do I fit (adjust if necessary) the above code into the code below?
And again, how do i adjust it to add various amounts for a total?


while (digitalRead(COIN)) {
delay(1);
counter++;
}
Serial.print(counter);
Serial.println(" ms long pulse");

if ((counter > 60) || (counter < 20))
return;

coins++;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" OINK OINK! ");
lcd.setCursor(0,1);
lcd.print("YOU HAVE $");
lcd.print(coins*.25);
lcd.print(" ");
// loop through to flash the LED



(please remember I am totally new at this so please no "do a search stupid or take a class first") I have read getting started with Arduino and other books and i can totally make an led blink!!! :wink:

User avatar
adafruit_support_bill
 
Posts: 88137
Joined: Sat Feb 07, 2009 10:11 am

Re: 4 coin piggy bank

Post by adafruit_support_bill »

The current code assumes equal values of 25.
Not really, the coin values are stored in the array (lines 11 & 12 of the code)
The array is indexed by the number of pulses (1-4). You can assign whatever values you like to the coins.

Code: Select all

const byte coinValues[4] = {
  5, 10, 20, 100}; //Coin values goes into this array

Pugsly
 
Posts: 3
Joined: Thu Feb 28, 2013 11:32 pm

Re: 4 coin piggy bank

Post by Pugsly »

adafruit_support wrote:
The current code assumes equal values of 25.
Not really, the coin values are stored in the array (lines 11 & 12 of the code)
The array is indexed by the number of pulses (1-4). You can assign whatever values you like to the coins.

Code: Select all

const byte coinValues[4] = {
  5, 10, 20, 100}; //Coin values goes into this array
Great, Ill try it.......well see how it goes.

Thanks

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”