4 coin piggy bank
Moderators: adafruit_support_bill, adafruit

4 coin piggy bank

by Pugsly on Thu Feb 28, 2013 10:40 pm

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
Pugsly
 
Posts: 3
Joined: Thu Feb 28, 2013 10:32 pm

Re: 4 coin piggy bank

by adafruit_support_bill on Fri Mar 01, 2013 8:22 am

There is a blog-post here with a link to the code : https://www.adafruit.com/blog/2012/04/2 ... in-action/
User avatar
adafruit_support_bill
 
Posts: 29218
Joined: Sat Feb 07, 2009 9:11 am

Re: 4 coin piggy bank

by Pugsly on Sat Mar 02, 2013 10:43 am

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:
Pugsly
 
Posts: 3
Joined: Thu Feb 28, 2013 10:32 pm

Re: 4 coin piggy bank

by adafruit_support_bill on Sat Mar 02, 2013 8:38 pm

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 | TOGGLE FULL SIZE
const byte coinValues[4] = {
  5, 10, 20, 100}; //Coin values goes into this array
User avatar
adafruit_support_bill
 
Posts: 29218
Joined: Sat Feb 07, 2009 9:11 am

Re: 4 coin piggy bank

by Pugsly on Sun Mar 03, 2013 7:37 am

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 | TOGGLE FULL SIZE
const byte coinValues[4] = {
  5, 10, 20, 100}; //Coin values goes into this array


Great, Ill try it.......well see how it goes.

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