#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
float sum = 0;
int quarterLedPin = 9;
int nickelLedPin = 8;
int pennyLedPin = 2;
int dimeLedPin = 16;
int masterLedPin = 17;
int state = 1;
int quarters = 0;
int nickels = 0;
int pennies = 0;
int dimes = 0;
int quarterState = 0;
int nickelState = 0;
int pennyState = 0;
int dimeState = 0;
int quarterStatePrev = 0;
int nickelStatePrev = 0;
int pennyStatePrev = 0;
int dimeStatePrev = 0;
int quarterPin = 13;
int nickelPin = 12;
int pennyPin = 11;
int dimePin = 10;
int quarterResetState = 0;
int nickelResetState = 0;
int pennyResetState = 0;
int dimeResetState = 0;
int masterResetState = 0;
int quarterResetStatePrev = 0;
int nickelResetStatePrev = 0;
int pennyResetStatePrev = 0;
int dimeResetStatePrev = 0;
int masterResetStatePrev = 0;
int quarterResetPin = 7;
int nickelResetPin = 6;
int pennyResetPin = 5;
int dimeResetPin = 4;
int masterResetPin = 3;
void setup()
{
lcd.begin(16, 2);
lcd.backlight();
pinMode(quarterLedPin, OUTPUT);
pinMode(nickelLedPin, OUTPUT);
pinMode(pennyLedPin, OUTPUT);
pinMode(dimeLedPin, OUTPUT);
pinMode(masterLedPin, OUTPUT);
pinMode(quarterPin, INPUT);
pinMode(nickelPin, INPUT);
pinMode(pennyPin, INPUT);
pinMode(dimePin, INPUT);
pinMode(quarterResetPin, INPUT);
pinMode(nickelResetPin, INPUT);
pinMode(pennyResetPin, INPUT);
pinMode(dimeResetPin, INPUT);
pinMode(masterResetPin, INPUT);
Serial.begin(9600);
}
void loop()
{
sum = (quarters * 0.25) + (nickels * 0.05) + (pennies * 0.01) + (dimes * 0.1);
lcd.setCursor(0, 0);
lcd.print(sum);
quarterStatePrev = quarterState;
nickelStatePrev = nickelState;
pennyStatePrev = pennyState;
dimeStatePrev = dimeState;
quarterState = digitalRead(quarterPin);
nickelState = digitalRead(nickelPin);
pennyState = digitalRead(pennyPin);
dimeState = digitalRead(dimePin);
quarterResetStatePrev = quarterResetState;
nickelResetStatePrev = nickelResetState;
pennyResetStatePrev = pennyResetState;
dimeResetStatePrev = dimeResetState;
masterResetStatePrev = masterResetState;
quarterResetState = digitalRead(quarterResetPin);
nickelResetState = digitalRead(nickelResetPin);
pennyResetState = digitalRead(pennyResetPin);
dimeResetState = digitalRead(dimeResetPin);
masterResetState = digitalRead(masterResetPin);
switch (state)
{
case 1:
if (quarterState == HIGH && quarterStatePrev == LOW)
{
quarters++;
}
if (nickelState == HIGH && nickelStatePrev == LOW)
{
nickels++;
}
if (pennyState == HIGH && pennyStatePrev == LOW)
{
pennies++;
}
if (dimeState == HIGH && dimeStatePrev == LOW)
{
dimes++;
}
if (quarterResetState == HIGH && quarterResetStatePrev == LOW)
{
quarters = 0;
}
if (nickelResetState == HIGH && nickelResetStatePrev == LOW)
{
nickels = 0;
}
if (pennyResetState == HIGH && pennyResetStatePrev == LOW)
{
pennies = 0;
}
if (dimeResetState == HIGH && dimeResetStatePrev == LOW)
{
dimes = 0;
}
if (masterResetState == HIGH && masterResetStatePrev == LOW)
{
quarters = 0;
nickels = 0;
pennies = 0;
dimes = 0;
}
digitalWrite(quarterLedPin, quarterState);
digitalWrite(nickelLedPin, nickelState);
digitalWrite(pennyLedPin, pennyState);
digitalWrite(dimeLedPin, dimeState);
digitalWrite(masterLedPin, masterResetState);
break;
default:
break;
}
}