Eccolo :o
[code]
#include <SD.h>
#include <RTClib.h>
#include <Wire.h>
RTC_DS1307 rtc;
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 lcd(0x27);
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
WidgetRTC blynk_rtc;
char auth[] = "";
char ssid[] = "Vodafone";
char pass[] = "xxxx";
char server[] = "blynk-cloud.com";
int port = 8080;
WidgetLCD blynk_lcd(V31);
WidgetLCD blynk1_lcd(V10);
BlynkTimer timer;
#define PORTA 1
#define POSTA 2
#define RESET 3
#define BANCONOTA5 5
#define BANCONOTA10 6
#define BANCONOTA20 7
#define BANCONOTA50 8
#define BANCONOTA100 10
int key[8] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH,};
int pin[8] = {BANCONOTA5, BANCONOTA10, BANCONOTA20, BANCONOTA50, BANCONOTA100, PORTA, POSTA, RESET,};
int banconota5 = 0;
int banconota10 = 0;
int banconota20 = 0;
int banconota50 = 0;
int banconota100 = 0;
//int posta = 1;
int porta = 1;
int sommapar = 0;
String postas = String (postas);
String posta = String ("VUOTO");
String posta1 = String ("PIENO");
File myFile;
File myFile1;
void setup()
{
WiFi.begin(ssid, pass);
Blynk.config(auth, server, port);
Blynk.connect();
Serial.begin(9600);
// Blynk.email("dellipaolmail.com", "CAMBIA MARIO", "acceso e connesso.");
timer.setInterval(90000L, leggidati );
timer.setInterval(300000L, leggidati1 );
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("SD non presente");
lcd.begin(16, 2);
lcd.setBacklight(255);
lcd.home(); lcd.clear();
lcd.setCursor(2, 0);
lcd.print(">V1.0<SD>KO ");
lcd.setCursor(0, 1);
lcd.print("SD NON PRESENTE");
while (1);
}
Serial.println("sd presente.");
lcd.begin(16, 2);
lcd.setBacklight(255);
lcd.home(); lcd.clear();
lcd.setCursor(4, 0);
lcd.print("SD > OK ");
lcd.setCursor(2, 1);
lcd.print("ATTENDERE>V1.0");
delay(3000);
char buf[20];
int i = 0;
while (myFile.available()) {
buf[i] = myFile.read());
i++;
if (i >= 19) break;
}
buf[i] = '\0';
sommapar = atoi(buf);
Serial.println(sommapar);
Wire.begin();
Wire.beginTransmission(0x27);
lcd.begin(16, 2);
lcd.setBacklight(255);
lcd.home(); lcd.clear();
lcd.setCursor(1, 0);
lcd.print("WIN GAMES");
lcd.setCursor(0, 1);
lcd.print("TOTALI");
delay(1000);
blynk1_lcd.clear();
blynk1_lcd.print(0, 0, postas );
blynk1_lcd.print(0, 1, "HOPPER,1" );
blynk_lcd.clear();
blynk_lcd.print(4, 0, sommapar );
blynk_lcd.print(4, 1, " TOTALI ");
for (int i = 0; i < 8 ; i++)
pinMode(pin[i], INPUT_PULLUP);
}
void loop()
{
int k;
for (int i = 0; i < 8 ; i++)
{
k = digitalRead(pin[i]);
if ( key[i] != k )
{
if ( key[i] == HIGH && k == LOW )
{
Serial.print("PIN");
Serial.println(pin[i]);
switch (pin[i])
{
case BANCONOTA5:
banconota5 = banconota5 + 5;
sommapar = banconota5 + banconota10 + banconota20 + banconota50 + banconota100;
SD.begin();
SD.remove("totali.txt");
myFile = SD.open("totali.txt", FILE_WRITE);
if (myFile) {
myFile.print(sommapar);
myFile.close();
Serial.println("salvata");
}
else {
Serial.println("error.txt");
}
myFile1 = SD.open("totali1.txt", FILE_WRITE);
if (myFile1) {
myFile1.print( "INSERITA BANCONOTA DA 5 EURO SOMMA PARZIALE = ");
myFile1.println(sommapar);
myFile1.close();
Serial.println("salvata1");
}
else {
Serial.println("error1.txt");
}
break;
case BANCONOTA10:
banconota10 = banconota10 + 10;
sommapar = banconota5 + banconota10 + banconota20 + banconota50 + banconota100;
Serial.println(" BANCONOTA 10");
break;
case BANCONOTA20:
banconota20 = banconota20 + 20;
sommapar = banconota5 + banconota10 + banconota20 + banconota50 + banconota100;
Serial.println(" BANCONOTA 20");
break;
case BANCONOTA50:
banconota50 = banconota50 + 50;
sommapar = banconota5 + banconota10 + banconota20 + banconota50 + banconota100;
Serial.println(" BANCONOTA 50");
break;
case BANCONOTA100:
banconota100 = banconota100 + 100;
sommapar = banconota5 + banconota10 + banconota20 + banconota50 + banconota100;
Serial.println(" BANCONOTA 100");
break;
case POSTA:
// Blynk.email("dellipaolil.com", "CAMBIO MARIO", "VUOTO");
postas = posta;
blynk1_lcd.print(0, 0, postas );
Serial.println(" POSTA");
break;
case PORTA:
Blynk.notify("ATTENZIONE PORTA APERTA ");
// Blynk.email("dellip@gmail.com", "CAMBIO MARIO", " CAMBIA MONETE \n ATTENZIONE PORTA APERTA ");
//blynk1_lcd.print(0, 0,stato );
Serial.println(" PORTA APERTA ");
break;
case RESET:
banconota5 = 0;
banconota10 = 0;
banconota20 = 0;
banconota50 = 0;
banconota100 = 0;
sommapar = 0;
postas = posta1 ;
Serial.println(" AZZERAMENTO TOTALI");
blynk_lcd.clear();
blynk1_lcd.clear();
lcd.home(); lcd.clear();
lcd.setCursor(0, 1);
lcd.print("TOTALI");
lcd.setCursor(1, 0);
lcd.print("AZZERAMENTO");
delay(3000);
lcd.home(); lcd.clear();
lcd.setCursor(1, 0);
lcd.print("WIN GAMES");
lcd.setCursor(0, 1);
lcd.print("TOTALI");
break;
}
Serial.print("Totale = ");
Serial.println(sommapar);
blynk_lcd.print(4, 0, sommapar );
blynk_lcd.print(4, 1, " TOTALI ");
blynk1_lcd.print(0, 0, postas );
blynk1_lcd.print(0, 1, "HOPPER,1" );
}
key[i] = k;
}
lcd.setCursor(8, 1);
lcd.print(sommapar);
}
if (Blynk.connected()) {
Blynk.run();
lcd.setCursor(11, 0);
lcd.print("CONN");
lcd.setCursor(11, 0);
}
else {
// Blynk.disconnect();
lcd.setCursor(11, 0);
lcd.print("DISC");
}
Blynk.run();
timer.run();
}
void leggidati() {
if (Blynk.connected()) {
WiFi.begin(ssid, pass);
Blynk.config(auth, server, port);
Blynk.connect();
}
else{
Blynk.connect();
Serial.println(sommapar);
blynk_lcd.print(4, 0, sommapar );
}
}
void leggidati1() {
if (Blynk.connected()) {
Serial.println("connesso");
}
else {
Serial.println("no connesso");
}
}
[/code]