#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd2(0x27,16,2);
const uint8_t buttonPins[] = { 7, 6, 5, 4, 3, 2 };
const int buttonTones[] = { 5, 10, 20, 50, 100, 200 };
int i = 0;
int i2 = -1;
int t = 0;
int time2 = 0;
int lastState[] = { 1, 1, 1, 1, 1, 1 };
int counts[] = { 0, 0, 0, 0, 0, 0 };
byte Spac[] = { 0b01010, 0b00100, 0b01010, 0b00100, 0b01010, 0b00100, 0b01010, 0b00100 };
byte Spac_Max[] = { 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111 };
void setup() {
lcd2.begin(20, 4);
lcd2.backlight();
//lcd.noBacklight();
for (uint8_t i = 0; i < 6; i++) { pinMode(buttonPins[i], INPUT_PULLUP); }
showSpalshScreen();
lcd2.createChar(0, Spac);
lcd2.createChar(5, Spac_Max);
}
void showSpalshScreen() {
lcd2.setCursor(1, 1);
String message = "Coin Counter v1.0";
for (byte i = 0; i < message.length(); i++) {
lcd2.print(message[i]);
delay(100);
}
delay(1000);
lcd2.clear();
digitalWrite(8, LOW);
}
void loop() {
for (uint8_t x = 0; x < 6; x++) {
int value = digitalRead((buttonPins[x]));
if (lastState[x] != value) {
lastState[x] = value;
if (value == HIGH) {
i += buttonTones[x];
counts[x] ++;
}
}
if (i != i2) {
i2 = i;
lcd2.setCursor(0, 0);
lcd2.print(String("5: ") + String(counts[0]));
lcd2.setCursor(9, 0);
lcd2.write(byte(0));
lcd2.print(String(" 50: ") + String(counts[3]));
lcd2.setCursor(0, 1);
lcd2.print(String("10: ") + String(counts[1]));
lcd2.setCursor(9, 1);
lcd2.write(byte(0));
lcd2.print(String(" 100: ") + String(counts[4]));
lcd2.setCursor(0, 2);
lcd2.print(String("20: ") + String(counts[2]));
lcd2.setCursor(9, 2);
lcd2.write(byte(0));
lcd2.print(String(" 200: ") + String(counts[5]));
lcd2.setCursor(0, 3);
lcd2.print(String("\357sszeg: ") + String(i) + String(" Ft"));
}
}
}