Project showcase
Regina - Electronic Version

Regina - Electronic Version © GPL3+

The sweet Portuguese Regina chocolate game. My electronic version.

  • 940 views
  • 0 comments
  • 0 respects

Components and supplies

12V DC Power Supply
×1
5V Voltage Regulator
×1
LED
×21
Wires
×1
Resistor 10k
×14
Key Switch
×1
Press Switch
×1
NPN Transistor
×7
11113 01
SparkFun Arduino Pro Mini 328 - 5V/16MHz
×1
LCD 16X2
×1
OON/OFF Switch
×1

About this project

The Story

Regina is a famous chocolate brand in Portugal and they have a card board game ('Fura Famliar') that consist in 20 holes that we punch to drop a small color ball, each color represents a kind of chocolate of the brand. It's a funny game to the kids, but in the end, when all the holes are punched the game goes to the garbage.

Last Christmas someone offered a 'Fura Famliar' to us and in the end I kept the cardbox thinking in these project.

The interesting facts are that the holes have the exact size of a 5mm LED support and the drawer where the balls falls have the exact size of a small LCD (I enlarged my own to feet a bigger display).

How It Works

The player has to click a button to randomly switch on a LED, in the display is given instructions and the name of the chocolate (or any other thing that you want)

There is a KEY switch to enable one shoot at a time.

After all the LEDs are ON we can make an reset to the game with a combination of switch/power and key.

The data of current ON LEDs are stored on EEPROM, with the limitation of 100,000 writes, this game can be reused for about 5000 times (100000 / 20 = 5000).

Video

'Fura Famliar' - Eletronic version of Regina chocolate cardboard game

Some Photos

Code

The Code - ArduinoC/C++
This is the main code. Was made very quickly so the are a lot of things that can be factorized... but it works well..
//Includes
#include <EEPROM.h> 
#include <LiquidCrystal.h>
#include <EEPROM.h>


//LCD pins definition and instantiation
const int rs = 12, en = 11, d4 = 13, d5 = 10, d6 = 9, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


//Software parameters
long shootingTime    = 5000;
long configDelayTime = 3000; //must be under 5000
int  giftsBurned;

bool burnedMsgFlag   = true;
bool showMsgFlag     = true;

//Led Matrix definition
//Array pos: 0->Order, 1->xPos, 2->yPos, 3->AlreadyBurned 
int LEDMatrix[20][4]={  
  
                      {1,A2,2,false}, {2,A4,2,false}, {3,A5,2,false}, {4,A0,2,false},
       {5,A1,3,false},{6,A2,3,false}, {7,A4,3,false}, {8,A5,3,false}, {9,A0,3,false}, {10,A3,3,false},
      {11,A1,4,false},{12,A2,4,false},{13,A4,4,false},{14,A5,4,false},{15,A0,4,false},{16,A3,4,false},
                      {17,A2,5,false},{18,A4,5,false},{19,A5,5,false},{20,A0,5,false},
};


int fullBurnedAddr = 20; //Address to store fullBurned value

//Special Chars
byte smile[8]={
  B00000,
  B10001,
  B00000,
  B00000,
  B10001,
  B01110,
  B00000,
};

byte bar[8]={
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
};


//Messages
String msg[]=
  {
    " CHAVE ATIVADA! ",
    "  VAMOS JOGAR   ",
    "DESLIGUE A CHAVE",
    "  PARA CONTIN.  ",
    "  PRESSIONE O   ",
    "    GATILHO!    ",
    "   BOA SORTE!   ",
    "GANHOU UM REGINA",
    "  EXPERIMENTE A ",
    "    SUA SORTE   "
  };

//List of Gifts
String gifts[20]=
  {
    " FRUTAS  ANANAS ",
    "    FLOC-CHOC   ",
    "    SOMBRINHA   ",
    "CHOCOLATE  LEITE",
    "     CLASSIC    ",
    "EXTRA NOIRE  70%",
    "    FLOC-CHOC   ",
    "EXTRA NOIRE  70%",
    "    SOMBRINHA   ",
    "     CLASSIC    ",
    "CHOCOLATE  LEITE",
    " FRUTAS MORANGO ",
    "EXTRA NOIRE  70%",
    "    FLOC-CHOC   ",
    "     CLASSIC    ",
    "    SOMBRINHA   ",
    "FRUTAS SILVESTRE",
    "CHOCOLATE  LEITE",
    "    SOMBRINHA   ",
    " FRUTAS LARANJA ",
  };




void setup() {
  
  long initTimmer = millis();

  //Serial communication just for debug (coment in the END)
  Serial.begin(9600);

  lcd.createChar(0, smile);
  lcd.createChar(1, bar);
  
  lcd.begin(16, 2);
  lcd.clear();
    
  //Inicialize LED matrix pins
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A4, OUTPUT);
  pinMode(A5, OUTPUT);
  pinMode(A0, OUTPUT);
  pinMode(A3, OUTPUT);
 
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  
  //Inicialize common pin of LED matrix PWM
  pinMode(6, OUTPUT);


   //LED brightness
  analogWrite(6, 255); 


  //Input Btn
  pinMode(A6, INPUT);  //pressure BT
  pinMode(A7, INPUT);  //key BT


  checkConfig();
 
  intializeArray();
}


void loop() {
   
  randomSeed(millis());
  
  if(isFullBurned()){
    showBurnedLEDs();
    if (burnedMsgFlag){
      showBurnedMsg();
    }
  }
  else{
    showBurnedLEDs();
    ckeckKeyActivation(); 
    if(showMsgFlag){
      showbaseMsg(); 
    }
  }
}





void showbaseMsg(){
  showMsgFlag = !showMsgFlag;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("   EXPERIMENTE  ");
  lcd.setCursor(0,1);
  lcd.print("   A SUA SORTE  ");
}

void checkConfig(){
  if(analogRead(A6) >= 50 & analogRead(A7) <= 50){
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(" TO RESET TURN  ");
    lcd.setCursor(0,1);
    lcd.print("THE KEY, HAVE 2s");
    delay(2000);
      if(analogRead(A7) >= 50){        
          resetArray();
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("   RESETTING..  ");
          lcd.setCursor(0,1);
          lcd.print("  TURN THE KEY  ");
          while(analogRead(A7) >= 50);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("  GAME RESETED  ");
          lcd.setCursor(0,1);
          lcd.print("   LET's PLAY   ");
          delay(2000);
          lcd.clear();
      }
      else
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("   TIME OUT!    ");
        delay(2000);
      }
  }
  
  showMsgFlag=true;
  
}

void showBurnedMsg(){
  lcd.setCursor(0,0);
  lcd.print(" JOGO  COMPLETO ");
  lcd.setCursor(0,1);
  lcd.print("    OBRIGADO!   ");
  burnedMsgFlag = !burnedMsgFlag;
  showMsgFlag=true;
}


void showBurnedLEDs(){
  for(int n=0; n<=19; n++){
      if(LEDMatrix[n][3]){
        digitalWrite(LEDMatrix[n][1],HIGH);digitalWrite(LEDMatrix[n][2],HIGH);
        digitalWrite(LEDMatrix[n][1],LOW);digitalWrite(LEDMatrix[n][2],LOW);
        delay(0);
      }
  }
}


void ckeckKeyActivation()
{ 
    if(analogRead(A7) >= 50){
      letsPlay();
    }
}


void letsPlay(){
       lcd.clear();
       lcd.setCursor(0,0);
       lcd.print(msg[0]);
       lcd.setCursor(0,1);
       lcd.print(msg[1]);
       delay(3000);
       lcd.setCursor(0,0);
       lcd.print(msg[2]);
       lcd.setCursor(0,1);
       lcd.print(msg[3]);
       while(analogRead(A7) >=50){}
       lcd.setCursor(0,0);
       lcd.print(msg[4]);
       lcd.setCursor(0,1);
       lcd.print(msg[5]);
       while(analogRead(A6) <=50){}
       lcd.clear();
       lcd.setCursor(0,0);
       lcd.print(msg[6]);
       randomShoot(shootingTime);

       showMsgFlag=true;
}


void randomShoot(long timmer){

  long initTime       = millis(); 
  long barTCtrl       = millis();
  long barLenghtRatio = timmer/16;
  int  barPos         = 0;
  
  int  xPos, yPos, randNumber;

  while(initTime >= millis()-timmer){
     randNumber = int(random(0,20));
    
     digitalWrite(LEDMatrix[randNumber][1],HIGH);digitalWrite(LEDMatrix[randNumber][2],HIGH);
     delay(20);
     digitalWrite(LEDMatrix[randNumber][1],LOW);digitalWrite(LEDMatrix[randNumber][2],LOW);
     lcd.setCursor(barPos,1);
     lcd.print(char(1));
     if (millis() - (barTCtrl+barLenghtRatio) <= barLenghtRatio)
     {
      barPos++;
      barTCtrl = millis();
     }
  }

  int gift = nextUnBurned(randNumber);
  
  LEDMatrix[gift][3] = true;
  writeToEEPROM(gift, true);
  
  digitalWrite(LEDMatrix[gift][1],HIGH);digitalWrite(LEDMatrix[gift][2],HIGH);
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(msg[7]);
  lcd.setCursor(0,1);
  lcd.print(gifts[gift]);
  while(analogRead(A6) <=50){}
  lcd.clear();

  showMsgFlag=true;
}


//Recursive function to give the next available Gift
int nextUnBurned(int rnd){
  if(LEDMatrix[rnd][3]){
    if (rnd >19) rnd = 0;
    rnd++;
    nextUnBurned(rnd);
  }
  else{
   return rnd;
  }
}


//Write to EEPROM function
void writeToEEPROM(int addr, bool val){
  EEPROM.write(addr, val);
}


//Inicialize LEDMatrix from values stored in EEPROM
void intializeArray(){
  for (int n=0; n<=19; n++){    
    if (EEPROM.read(n)==1){
      LEDMatrix[n][3] = true;
    }else{
      LEDMatrix[n][3] = false;
    }
  }
}


bool isFullBurned(){
 
  giftsBurned = 0;
  
  for (int n=0; n<=19; n++){     
    if (LEDMatrix[n][3]==true){
      giftsBurned++;
      }
   }

   if (giftsBurned >= 20){
      return true;
   }else{
      return false;
   }
}


void resetArray(){
  for (int n=0; n<=19; n++){    
    EEPROM.write(n,false);
  }
}

Schematics

Diagram
this is the electronic schematic

Comments

Similar projects you might like

Electronic Wind DIY Pinwheel

Project tutorial by Francesco Guerri

  • 2,747 views
  • 0 comments
  • 8 respects

CUTSIE WHUN Version 2 - The Ultimate Balancing Robot

Project in progress by Pigeon-Kicker

  • 1,465 views
  • 0 comments
  • 8 respects

Electronic Music

Project showcase by Glauber Santiago

  • 1,261 views
  • 1 comment
  • 0 respects

Electronic Safe with Arduino

Project showcase by chummer1010

  • 24,874 views
  • 28 comments
  • 54 respects

Talking Clock 2 - New Version (Bilingual: EN-PT)

Project tutorial by LAGSILVA

  • 7,350 views
  • 19 comments
  • 33 respects

New Electronic Music Instrument Design

Project showcase by cpeckmusic

  • 4,303 views
  • 0 comments
  • 16 respects
Add projectSign up / Login