Tente este codigo:
//https://forum.arduino.cc/t/projeto-com-fita-rgb-com-leds-fracos-ajuda/1240753/8
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define LEDPIN 13
#define HOME_SENSORPIN 7
#define AWAY_SENSORPIN 4
#define dcasa 8
#define dfora 2
#define BRIGHTNESS 80
LiquidCrystal_I2C lcd(0x27, 16, 2);
const char HOME_TEAM[] = "SPORTING ";
const char AWAY_TEAM[] = "BENFICA ";
//RGB
int vermelho = 10;
int verde = 11;
int azul = 12;
int home_goals = 0;
int away_goals = 0;
int home_wins = 0;
int away_wins = 0;
int homeSensorState = 0, homeLastState = 0; // variable for reading the pushbutton status
int awaySensorState = 0, awayLastState = 0; // variable for reading the pushbutton status
int dcasaState = 0, dcasaLastState = 0;
int dforaState = 0, dforaLastState = 0;
//-------------------------------------------------------------
void printScore() {
// Write home info
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(HOME_TEAM);
if (home_goals < 10) {
lcd.print(" ");
}
lcd.print(home_goals);
if (home_wins < 10) {
lcd.print(" ");
}
// Write away info
lcd.setCursor(0, 1);
lcd.print(AWAY_TEAM);
if (away_goals < 10) {
lcd.print(" ");
}
lcd.print(away_goals);
if (away_wins < 10) {
lcd.print(" ");
}
}
//---------------------------------------------------------------------
void setColor(int redValue, int greenValue, int blueValue) {
//analogWrite(vermelho, redValue);
//analogWrite(verde, greenValue);
//analogWrite(azul, blueValue);
// Serial.println("Apaga tudo");
digitalWrite(vermelho, !redValue);
digitalWrite(verde, !greenValue);
digitalWrite(azul, !blueValue);
}
//---------------------------------------------------------------------
void piscared() {
setColor(255, 0, 0);
}
//---------------------------------------------------------------------
void piscagreen() {
setColor(0, 0, 255);
}
//---------------------------------------------------------------------
void apagado() {
setColor(0, 0, 0);
}
//-------------------------------------------------------------
void splashScreen() {
int i = 0;
int j = 0;
for (i = 0; i < 2; i++) {
for (j = 0; j < 16; j++) {
//lcd.clear();
lcd.setCursor(j, i);
lcd.print("-");
delay(25);
}
}
}
//-------------------------------------------------------------
void blinkHome() {
Serial.println("blinkHome");
piscagreen();
delay(150);
apagado();
delay(150);
piscagreen();
}
//-------------------------------------------------------------
void blinkAway() {
Serial.println("blinkAway");
piscared();
delay(150);
apagado();
delay(150);
piscared();
}
//-------------------------------------------------------------
void printGoalHOME() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GOLO GOLO GOLO");
lcd.setCursor(0, 1);
lcd.print(" SPORTING ");
delay(1100);
}
//---------------------------------------------------------------------
void printGoalAWAY() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GOLO GOLO GOLO");
lcd.setCursor(0, 1);
lcd.print(" BENFICA ");
delay(1100);
}
void printGoalmenos() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" INVALIDO ");
lcd.setCursor(0, 1);
lcd.print(" ANULADO ");
delay(500);
}
//-------------------------------------------------------------
void setup() {
// set up the LCD's number of columns and rows:
lcd.init();
lcd.backlight();
// Print a message to the LCD.
//lcd.print("hello, world!");
printScore();
// initialize the LED pin as an output:
pinMode(LEDPIN, OUTPUT);
// initialize the sensor pin as an input:
pinMode(HOME_SENSORPIN, INPUT);
digitalWrite(HOME_SENSORPIN, HIGH); // turn on the pullup
pinMode(AWAY_SENSORPIN, INPUT);
digitalWrite(AWAY_SENSORPIN, HIGH); // turn on the pullup
pinMode(dcasa, INPUT);
digitalWrite(dcasa, HIGH);
pinMode(dfora, INPUT);
digitalWrite(dfora, HIGH);
pinMode(vermelho, OUTPUT);
pinMode(verde, OUTPUT);
pinMode(azul, OUTPUT);
Serial.begin(9600);
setColor(0, 0, 0);
}
//---------------------------------------------------------------------
void loop() {
homeSensorState = digitalRead(HOME_SENSORPIN);
awaySensorState = digitalRead(AWAY_SENSORPIN);
dcasaState = digitalRead(dcasa);
dforaState = digitalRead(dfora);
if (homeSensorState == LOW) {
digitalWrite(LEDPIN, HIGH);
}
else {
digitalWrite(LEDPIN, LOW);
}
if (awaySensorState == LOW) {
digitalWrite(LEDPIN, HIGH);
}
else {
digitalWrite(LEDPIN, LOW);
}
if (homeSensorState && !homeLastState) {
Serial.println("home Unbroken");
}
if (!homeSensorState && homeLastState) {
Serial.println("home Broken");
printGoalHOME();
blinkHome();
blinkHome();
blinkHome();
blinkHome();
blinkHome();
blinkHome();
apagado();
home_goals++;
printScore();
if (home_goals == 5) {
if (home_goals > away_goals) {
home_wins++;
}
else {
away_wins++;
}
home_goals = 0;
away_goals = 0;
delay(2000);
printScore();
}
}
if (dcasaState == LOW) {
digitalWrite(LEDPIN, HIGH);
}
else {
digitalWrite(LEDPIN, LOW);
}
if (dforaState == LOW) {
digitalWrite(LEDPIN, HIGH);
}
else {
digitalWrite(LEDPIN, LOW);
}
if (dcasaState && !dcasaLastState) {
Serial.println("home Unbroken");
}
if (!dcasaState && dcasaLastState) {
Serial.println("home Broken");
printGoalmenos();
home_goals--;
printScore();
if (home_goals == 5) {
if (home_goals > away_goals) {
home_wins++;
}
else {
away_wins++;
}
home_goals = 0;
away_goals = 0;
delay(2000);
printScore();
}
}
if (awaySensorState && !awayLastState) {
Serial.println("away Unbroken");
}
if (!awaySensorState && awayLastState) {
Serial.println("away Broken");
printGoalAWAY();
blinkAway();
blinkAway();
blinkAway();
blinkAway();
blinkAway();
blinkAway();
apagado();
away_goals++;
printScore();
if (away_goals == 5) {
if (away_goals > home_goals) {
away_wins++;
}
else {
home_wins++;
}
away_goals = 0;
home_goals = 0;
delay(2000);
printScore();
}
}
if (dforaState && !dforaLastState) {
Serial.println("away Unbroken");
}
if (!dforaState && dforaLastState) {
Serial.println("away Broken");
printGoalmenos();
away_goals--;
printScore();
if (away_goals == 5) {
if (away_goals > home_goals) {
away_wins++;
}
else {
home_wins++;
}
away_goals = 0;
home_goals = 0;
delay(2000);
printScore();
}
}
homeLastState = homeSensorState;
awayLastState = awaySensorState;
dcasaLastState = dcasaState;
dforaLastState = dforaState;
}