JULIO CESAR DA MOTA LIMEIRA
Published © GPL3+

Score counter

A arduino programmed score counter using two buttons, a potentiometer that regulates the maximum score and an LCD for display information

BeginnerFull instructions provided1 hour209
Score counter

Things used in this project

Story

Read more

Schematics

Score count

Code

Score count

C Header File
The code works in a C script for arduino uno that checks for the switch inputs and transforms in score for a team, when the score reaches the max stated by the potentiometer, the program prints the winning team on the LCD and the buzzer emits a buzz, then resets and checks for the max score again.
#include <LiquidCrystal.h>

const int rs = 3, en = 4, d4 = A2, d5 = A3, d6 = A4, d7 = A5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

const int botaoTimeA = 7; // Pino para o botão do Time A
const int botaoTimeB = 6; // Pino para o botão do Time B
const int buzzer = 10;

int pontosTimeA = 0; // Pontuação inicial do Time A
int pontosTimeB = 0; // Pontuação inicial do Time B
int MAX_POINTS;

void setup() {
  Serial.begin(9600);

  lcd.begin(16, 2);
  MAX_POINTS = map(analogRead(0),0,1023,1,12);
  lcd.print("pontuacao MAX");
  lcd.setCursor(0, 1);
  lcd.print(MAX_POINTS);
  delay(1000);
  
  lcd.clear();
  lcd.print("Time A: 0");
  lcd.setCursor(0, 1);
  lcd.print("Time B: 0");
  
  pinMode(buzzer, OUTPUT);
  pinMode(botaoTimeA, INPUT_PULLUP);
  pinMode(botaoTimeB, INPUT_PULLUP);
  
}

void loop() {
    
  if (digitalRead(botaoTimeA) == LOW) {
    aumentarPontosTimeA();
    delay(500); // Atraso para evitar múltiplas contagens
  }

  if (digitalRead(botaoTimeB) == LOW) {
    aumentarPontosTimeB();
    delay(500); // Atraso para evitar múltiplas contagens
  }

  if (pontosTimeA == MAX_POINTS || pontosTimeB == MAX_POINTS){
    newGame();
    delay(500);
    
  }
}


void aumentarPontosTimeA() {
  pontosTimeA++;
  atualizarDisplay();
}

void newGame(){
  delay(1000);
  int tempo = 400;
  tone(10,440,tempo); //LA

  lcd.clear();
  if(pontosTimeA > pontosTimeB){
    lcd.print("Time A wins!");
  }
  else{
    lcd.print("Time B wins!");
  }
  delay(3000);
  lcd.clear();
  MAX_POINTS = map(analogRead(0),0,1023,1,12);
  lcd.print("pontuacao MAX");
  lcd.setCursor(0, 1);
  lcd.print(MAX_POINTS);
  delay(1000);

  lcd.clear();
  

  
 delay(1000); // Atraso para evitar múltiplas contagens
 pontosTimeA = 0;
 pontosTimeB = 0;
 atualizarDisplay(); 
}

void aumentarPontosTimeB() {
  pontosTimeB++;
  atualizarDisplay();
}

void atualizarDisplay() {
  lcd.clear();
  lcd.print("Time A: ");
  lcd.print(pontosTimeA);
  lcd.setCursor(0, 1);
  lcd.print("Time B: ");
  lcd.print(pontosTimeB);
}

Credits

JULIO CESAR DA MOTA LIMEIRA
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.