The new Raspberry Pi B Model B+ is here - Pick one up in the store and check our detailed guide!

First Arduino Table Soccer

by pighixxx on Sun Jun 30, 2013 5:49 am

Image

Image

Image

Image

Image

Image

Image

Built in Bassano at 2nd Arduino National Forum Meeting :D

http://www.youtube.com/watch?v=KLEhGhvZ ... e=youtu.be
User avatar
pighixxx
 
Posts: 81
Joined: Tue Feb 12, 2013 6:25 am

Re: First Arduino Table Soccer

by adafruit_support_bill on Sun Jun 30, 2013 8:05 am

Blogged! Thanks for posting :D
User avatar
adafruit_support_bill
 
Posts: 27961
Joined: Sat Feb 07, 2009 9:11 am

Re: First Arduino Table Soccer

by pighixxx on Sun Jun 30, 2013 11:05 am

Made by PaoloP, Uwefield, Ratto93, LucaMarkio
Thanks again!!
User avatar
pighixxx
 
Posts: 81
Joined: Tue Feb 12, 2013 6:25 am

Re: First Arduino Table Soccer

by pighixxx on Sun Jun 30, 2013 12:34 pm

The code:

Code: Select all | TOGGLE FULL SIZE
// Arduined Soccer Table
// by PaoloP, LucaMarkio, Uwefed, Ratto93 & C.

#define PINRESET 5
#define SENSORA A0
#define SENSORB A1

#include <TM1638.h> // https://code.google.com/p/tm1638-library/

// define a module on data pin 8, clock pin 9 and strobe pin 7
TM1638 module(8, 9, 7);

byte scoreA, scoreB;

void setup(){
  pinMode(PINRESET, INPUT_PULLUP);
  delay(1000);
  Serial.begin(9600);
  Serial.println(F("Start"));
  scoreA = 0;
  scoreB = 0;
}

void loop(){
  printScore();
  if (digitalRead(PINRESET) == LOW){
    module.clearDisplay();
    delay(200);
    scoreA=0;
    scoreB=0;
  }
  int sensA = analogRead(SENSORA);
  int sensB = analogRead(SENSORB);
  if (sensA < 512){
    Serial.println("Goal!! A");
    scoreA++;
    goalSignal(2);
  }
  if (sensB < 512){
    Serial.println("Goal!! B");
    scoreB++;
    goalSignal(1);
  }
}

void goalSignal (byte team){
  for(byte j=0; j<3; j++){
    for(byte x=0; x<8; x++){
      module.setLED(team, x);
    }
    delay(100);
    for(byte x=0; x<8; x++){
      module.setLED(0, x);
    }    
    delay(100);
  }
}

void printScore (void)
{
  Serial.print(scoreA);
  if (scoreA<10) {
    module.setDisplayDigit(scoreA,0,0);
  }
  else
  {
    module.setDisplayDigit(scoreA%10,1,0);
    module.setDisplayDigit(scoreA/10,0,0);
  }
  Serial.print(" - ");
  Serial.print(scoreB);
  if (scoreB<10) {
    module.setDisplayDigit(scoreB,7,0);
  }
  else
  {
    module.setDisplayDigit(scoreB%10,7,0);
    module.setDisplayDigit(scoreB/10,6,0);
  }
  Serial.println("");
}
User avatar
pighixxx
 
Posts: 81
Joined: Tue Feb 12, 2013 6:25 am