Difference between revisions of "Bingo Game Machine 02"

From Microduino Wiki
Jump to: navigation, search
(Created page with "{| style="width: 1000px;" |- | ==Overview== 600px|center Align the numbers 1-6 on the second line with the random number on the first line...")
(No difference)

Revision as of 08:13, 24 March 2017

Overview

Anywhere Bingo game 1.jpg

Align the numbers 1-6 on the second line with the random number on the first line (if the random number is 2, align the 2 on the second line to it) through turning the potentiometer, after the numbers are aligned, the buzzer will buzz and Score+1.

Analysis In Bingo Game Machine 01, the range of b is set to 0-90. List the correspondence relation formula according to the values of a and b on the picture:

a = (b+18) / 18, simplified into a = b / 18+1


The requirement of the alignment as so is very high, which can’t stand for a little deviation. It is too difficult. So alignment just in a range is OK.

Anywhere Bingo game 2 analysis1.jpg

In Bingo Game Machine 01, the range of b is set to 0-90. We can judge the number to be aligned through a equation: aligned number=(b+27)/18

Anywhere Bingo game 2 analysis2.jpg

Module List

Module

Module Number Function
mCookie-Core 1 Core board
Battery base 1 Program download and power supply
mCookie-Hub 1 Sensor adapter plate
mCookie-OLED 1 Display
Potentiometer 1 Detect rotation
Buzzer 1 Produce sound

Other Equipment

  • USB cable*1
  • Sensor cable*2
  • Sensor shell
  • Lego or other fixation structures
Anywhere Bingo game 2-module.jpg

Module Setup

Setup

Anywhere Bingo game 2-step.jpg
  • Assemble modules and sensors together:
    • Stick the red core module, battery base, OLED and green Hub together;
    • Connect the Buzzer to pin 8/9 of Hub;
    • Connect the potentiometer to pin A0 of Hub;
    • Plug one end of the USB cable into the battery base, and connect the other to the computer;

Program

Programming Thought

Declare variables for storing data, write function start for producing random numbers, producing a random number when the condition is matched; write function display for display on OLED, displaying the game interface on OLED; write function BINGO for judging the alignment, after alignment, score+1 and the buzzer buzzes. Finally, execute all functions.

Mixly-ctrl-Bingo game 2.jpg

Required Program Blocks

Start to Program

1. Declare variables for storing data
Variable bingo if for storing the alignment state of numbers

Mixly-ctrl-mixly-ctrl-Bingo game 2-code.jpg


2. Write function start for producing random numbers, producing one each time
If variable bingo is 1 (the numbers have been aligned, so it can reproduce a new random number), produce a new random number, set variable bingo to 0.

Mixly-ctrl-Bingo game 2-code1.jpg

3. Write function display for display on OLED
Function display isn’t changed.

Mixly-ctrl-Bingo game 2-code2.jpg


4. Write function BINGO, when the numbers are aligned, the buzzer buzzes and score one
If the result of (b+27) /18 is a (the numbers have been aligned), set bingo to 1 (inform function start: numbers are aligned), score adds 1 (score) and buzzer buzzes once.

Mixly-ctrl-Bingo game 2-code3.jpg


5. Execute functions
Execute “start”, “display” and “BINGO” three functions

Mixly-ctrl-Bingo game 2-code4.jpg



Test the result
After upload, display a random number on the first line of the OLED, display “1 2 3 4 5 6” on the second line and display SCORE: 0 on the third line. Tuning the potentiometer, the “1 2 3 4 5 6” can be moved. When the random number is aligned to the corresponding number, SCORE on the third line adds 1, and buzzer buzzes.

Anywhere Bingo game 1.jpg



Q: If two random numbers produced in two successive times are same, you can get points successively, that is unfair!
A: Confirm the random number produced this time is different from the last one. If it is same with the last once, reproduce one until it is different from the last one

A new variable is needed for storing the new random number (a_random), when the current random number is same to the new one, reproduce one. Otherwise, save the value of a_random into a. Keep function BINGO and display unchanged.

Mixly-ctrl2-Bingo game 2.jpg


Programming

Mixly-ctrl-Bingo game 2-code5.jpg

Technical Specification

Relative Cases

FAQ