circuito bingo

Tombola is a traditional Italian board game that is usually played with the family during the Christmas holidays. Bingo is a game of chance played all over the world (in the USA the game is played with 75 numbers).

We program with Arduino a sketch that implements a C function that generates a succession of 90 bingo or tombola numbers. To test the feature of this function, each time you press a button (with debounce) the software prints a new number. The extraction of numbers can also be carried out with automatic extraction, for example every 5 seconds inside the loop(). The circuit diagram is minimal, as you can see in the figure.

In the sketch shown, the proposed function int* getNumbers() returns the pointer to the memory location *RAMlocation from which the vector of the extracted numbers, called bingo[90], is stored. Each time you press a button (with debounce), connected to pin 4, the software prints a new, not yet extracted, number.

 

/* Function that generates a sequence of 90 bingo numbers. 
Each time you press a button (with debounce) the software 
prints a new number */
#define pushButton 4
int bingo[90];
int *RAMlocation;
int i;
int presentState, previousState=0;

int* getNumbers(){
  static int numbers[90], extractedNumber;
  int i=0,k;
  randomSeed(analogRead(0));
  bool alreadyExtracted;
  do {
      alreadyExtracted = false;
      extractedNumber = random(1, 91);
      for (k=0; k<i;k++) {
        if (extractedNumber == numbers[k]) {
              alreadyExtracted = true;
            }
       }
       if (alreadyExtracted == false) { 
            numbers[i]=extractedNumber;
            i++;
          }
    } while(i<90);
  return (&numbers[0]);
}

void setup(){    Serial.begin(9600);    RAMlocation = getNumbers();  for (i = 0; i < 90; i++) {      bingo[i]=*(RAMlocation + i);      /* The following two lines are for debugging:      you can remove them */      Serial.print(bingo[i]);      Serial.print(" ");      }    Serial.println();  pinMode(pushButton, INPUT);  i=0; } void loop() {  presentState=digitalRead(pushButton);  if ((presentState==1) && (previousState==0))  {    Serial.print(bingo[i]);    Serial.print(" ");    i++;  }  previousState=presentState; }

Here you can find the simulation of the Arduino sketch with Tinkercad: Tombola function (Bingo). I also propose a simple code in ANSI C that you can try with Ideone: tombola.c or other C compiler.

#include <stdio.h>
#include <stdlib.h>
int tombola[90], estratto;
int i=0,k;
int giaestratto; // boolean<
int mainvoid) {
  srand(time(NULL));
  do {
    giaestratto=0;
    estratto = rand()%90+1;
    for (k=0; k<i;k++) {
      if (estratto == tombola[k])
          {
            giaestratto=1;
          }
    }
     if (giaestratto==0) { 
          tombola[i]=estratto;
          printf("\t%d",tombola[i]);
          i++;
        }
  } while(i<90);
}

Advertising

Advertising

Advertising