Per capire cosa non funziona ho aggiunto la seriale. Ora il codice è questo:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int SelettoreA;
int SelettoreB;
int SelettoreC;
int Reset_pezzi;
int F_Cellula;
int pezziA = 0;
int pezziB = 0;
int pezziC = 0;
int pausa=100;
void setup ()
{
lcd.begin(16, 2);
Serial.begin(9600);
pinMode (0, INPUT);
pinMode (10, INPUT);
pinMode (11, INPUT);
pinMode (12, INPUT);
pinMode (13, INPUT);
lcd.setCursor(0, 0);
lcd.print("conteggio");
lcd.setCursor(0, 1);
lcd.print("pezzi");
delay(3000);
lcd.clear();
}
void loop ()
{
SelettoreA=digitalRead(0);
SelettoreB=digitalRead(10);
SelettoreC=digitalRead(11);
Reset_pezzi=digitalRead(12);
F_Cellula=digitalRead(13);
//__________________________________________________________
if (SelettoreA==HIGH){
lcd.setCursor(0, 0);
lcd.print("Pezzi TIPO A");
Serial.print("Pezzi TIPO A");
Serial.print("\n\r");
}
if ((SelettoreA==HIGH) && (F_Cellula==HIGH)){
pezziA++;
lcd.setCursor(0, 1);
lcd.print(pezziA);
Serial.print(pezziA);
Serial.print("\n\r");
delay(pausa);
}
//__________________________________________________________
if (SelettoreB==HIGH){
lcd.setCursor(0, 0);
lcd.print("Pezzi TIPO B");
Serial.print("Pezzi TIPO B");
Serial.print("\n\r");
}
if ((SelettoreB==HIGH) && (F_Cellula==HIGH)){
pezziB++;
lcd.setCursor(0, 1);
lcd.print(pezziB);
Serial.print(pezziB);
Serial.print("\n\r");
delay(pausa);
}
//__________________________________________________________
if (SelettoreC==HIGH){
lcd.setCursor(0, 0);
lcd.print("Pezzi TIPO C");
Serial.print("Pezzi TIPO C");
Serial.print("\n\r");
}
if ((SelettoreC==HIGH) && (F_Cellula==HIGH)){
pezziC++;
lcd.setCursor(0, 1);
lcd.print(pezziC);
Serial.print(pezziC);
Serial.print("\n\r");
delay(pausa);
}
//__________________________________________________________
if ((SelettoreA==HIGH) && (Reset_pezzi==HIGH)){
pezziA=0;
Serial.print("Reset Pezzi TIPO A");
Serial.print("\n\r");
delay(pausa);
}
if ((SelettoreB==HIGH) && (Reset_pezzi==HIGH)){
pezziB=0;
Serial.print("Reset Pezzi TIPO B");
Serial.print("\n\r");
delay(pausa);
}
if ((SelettoreC==HIGH) && (Reset_pezzi==HIGH)){
pezziC=0;
Serial.print("Reset Pezzi TIPO C");
Serial.print("\n\r");
delay(pausa);
}
}
Aprendo il serial monito mi appare questo:
Pezzi TIPO A
Pezzi TIPO B
Pezzi TIPO C
Reset Pezzi TIPO A
Reset Pezzi TIPO B
Reset Pezzi TIPO C
Pezzi TIPO A
Pezzi TIPO B
Pezzi TIPO C
Reset Pezzi TIPO A
Reset Pezzi TIPO B
Reset Pezzi TIPO C
Pezzi TIPO A
Pezzi TIPO B
Pezzi TIPO C
Reset Pezzi TIPO A
Reset Pezzi TIPO B
Reset Pezzi TIPO C
Pezzi TIPO A
Pezzi TIPO B
Pezzi TIPO C
Reset Pezzi TIPO A
Reset Pezzi TIPO B
Reset Pezzi TIPO C
Pezzi TIPO A
Pezzi TIPO B
Pezzi TIPO C
Reset Pezzi TIPO A
Reset Pezzi TIPO B
Reset Pezzi TIPO C
Pezzi TIPO A
Pezzi TIPO B
Pezzi TIPO C
Reset Pezzi TIPO A
Reset Pezzi TIPO B
Reset Pezzi TIPO C
Pezzi TIPO A
Pezzi TIPO B
Pezzi TIPO C
Reset Pezzi TIPO A
Reset Pezzi TIPO B
Reset Pezzi TIPO C
Pezzi TIPO A
Pezzi TIPO B
Pezzi TIPO C
Reset Pezzi TIPO A
Reset Pezzi TIPO B
Reset Pezzi TIPO C
Pezzi TIPO A
Pezzi TIPO B
Pezzi TIPO C
Reset Pezzi TIPO A
Reset Pezzi TIPO B
Reset Pezzi TIPO C
Pezzi TIPO A
Pezzi TIPO B
Come se tutti gli ingressi fossero ad "1"
Io però ho aggiunto delle resistenze da 10K tra i pin interessati e il GND
Cosa mi sfugge?