3
« on: April 18, 2012, 08:04:34 pm »
The project was born as a table football score counter.
It was my first project and it's very simple.
Clicking on one of the two buttons you increment a variable for the score of each team. By the difference from the two values the software print on an lcd messages like: Reds takes the lid, or OMG It's over 9000! or I don't know, whatever you want. Then during the play you can se the two scores printed on screen. If you want you can also use a flex sensor to automatically increment the variable when taking a point.
You can also create a cycle to get a game with only 10 balls.
You reset the values reinitializing arduino pushing the reset button.
There are two buttons connected with the pin 2 and 3 of arduino.
The lcd is connected as follow:
16 LED- to Gnd
15 LED+ to 5V
14-11 DB 7-4 to 12, 11, 10, 9
10-7 Unused
6 E to 8
5 R/W to Gnd (unused)
4 RS to 7
3 V0 to a 10K ohm potentiometer
2 VDD to 5V
1 VSS to Gnd
Here the code (I'm sorry but messages are in italian... Really, I don't know how to translate them XD)
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
const int RbuttonPin = 2;
const int BbuttonPin = 3;
int RbuttonPushCounter = 0;
int RbuttonState = 0;
int RlastButtonState = 0;
int BbuttonPushCounter = 0;
int BbuttonState = 0;
int BlastButtonState = 0;
void setup() {
lcd.begin(16, 2);
lcd.print("Rossi vs Blu");
pinMode(RbuttonPin, INPUT);
pinMode(BbuttonPin, INPUT);
}
void loop() {
RbuttonState = digitalRead(RbuttonPin);
BbuttonState = digitalRead(BbuttonPin);
lcd.setCursor(0, 0);
lcd.print("Rossi vs Blu");
//INCREMENTO ROSSO
if (RbuttonState != RlastButtonState) {
if (RbuttonState == HIGH) {
RbuttonPushCounter++;
if (BbuttonPushCounter - RbuttonPushCounter == 1)
{lcd.setCursor(0, 0);
lcd.print(" La rimonta ");
lcd.setCursor(0, 1);
lcd.print(" dei rossi! ");
delay(2000); }
if (BbuttonPushCounter - RbuttonPushCounter == 0)
{lcd.setCursor(0, 0);
lcd.print("Le squadre sono ");
lcd.setCursor(0, 1);
lcd.print(" Testa a testa ");
delay(2000);
}
if (BbuttonPushCounter - RbuttonPushCounter == -1)
{lcd.setCursor(0, 0);
lcd.print("I rossi passano ");
lcd.setCursor(0, 1);
lcd.print(" in vantaggio ");
delay(2000);
}
if (BbuttonPushCounter - RbuttonPushCounter == -6)
{lcd.setCursor(0, 0);
lcd.print(" OMG! ");
lcd.setCursor(0, 1);
lcd.print(" It's over 9000 ");
delay(2000);
}
}
}
RlastButtonState = RbuttonState;
//INCREMENTO BLU
if (BbuttonState != BlastButtonState) {
if (BbuttonState == HIGH) {
BbuttonPushCounter++;
if (BbuttonPushCounter - RbuttonPushCounter == -1)
{lcd.setCursor(0, 0);
lcd.print(" La rimonta ");
lcd.setCursor(0, 1);
lcd.print(" dei blu! ");
delay(2000); }
if (BbuttonPushCounter - RbuttonPushCounter == 0)
{lcd.setCursor(0, 0);
lcd.print("Le squadre sono ");
lcd.setCursor(0, 1);
lcd.print(" Testa a testa ");
delay(2000);
}
if (BbuttonPushCounter - RbuttonPushCounter == 1)
{lcd.setCursor(0, 0);
lcd.print(" I blu passano ");
lcd.setCursor(0, 1);
lcd.print(" in vantaggio ");
delay(2000);
}
if (BbuttonPushCounter - RbuttonPushCounter == 6)
{lcd.setCursor(0, 0);
lcd.print(" OMG! ");
lcd.setCursor(0, 1);
lcd.print(" It's over 9000 ");
delay(2000);
}
}
}
BlastButtonState = BbuttonState;
lcd.setCursor(0, 1);
lcd.print(RbuttonPushCounter);
if (RbuttonPushCounter<10) {
lcd.print(" - ");
} else {
lcd.print(" - ");
}
lcd.print(BbuttonPushCounter);
}