Bingo Game Machine 03

From Microduino Wiki
Revision as of 07:22, 27 March 2017 by Zhangfengfeng (talk) (Q&A)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Overview

Anywhere Bingo game 1.jpg

Optimize the program of position detection, preventing scoring through turning the potentiometer casually.

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

OtherEquipment

  • USB cable*1
  • Sensor cable*2
  • Sensor shell
  • Building blocks 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 rotating potentiometer to pin A0 of Hub;
    • Plug one end of USB cable into the battery base and connect the other to the computer.

Programming

Programming Thought

After the alignment judgment is matched, if the value of the potentiometer keeps unchanged after 100ms, the alignment is completed and other program keeps unchanged.

Mixly-ctrl-Bingo game 3.jpg

Required Program Blocks

Start to Program

1. Declare variables for storing data
Variable a is for storing the random number, a_random is for storing random changed number, b is for storing the movement range of texts, score is for storing score, bingo is for storing the alignment state of numbers, hold is for storing the initial value of the potentiometer at the moment when numbers are aligned.

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


2. Change the contend of function bingo
If numbers are aligned, save the value of the potentiometer in hold (the one used here is the initial value without conversion, because the initial value is more exact), then delay for 100ms, after that, if the value of the potentiometer is equivalent to hold (during the 100ms, the potentiometer isn’t turned), that can be thought as the numbers are aligned, execute the program that score and buzzer buzzes.

Mixly-ctrl-Bingo game 3-code1.jpg

3. Start function and display function needn’t to be changed

Mixly-ctrl-Bingo game 3-code2.jpg


4. Execute functions
Finally, just execute every functions.

Mixly-ctrl-Bingo game 3-code3.jpg



Test the result
After upload, display a new random number on the first line of OLED, display “1 2 3 4 5 6” on the second line, and display SCORE:0 on the third. Move “1 2 3 4 5 6” with the potentiometer, when the random number is aligned to the corresponding number, and the potentiometer keeps still for 100ms, the score on the third line will increase 1, and the buzzer will buzz.

Anywhere Bingo game 1.jpg



Q: Now, only after the numbers are aligned can the random number change, how to make it can change once in a while, to increase the difficulty of the game?
A: We can add a timer function, if a certain time is over, reproduce a random number

Time after producing the random number, when 3000ms is over, the buzzer will buzz lowly, and red LED will flash once, set miss to 1 (reproduce a random number).

Mixly-ctrl2-Bingo game 3.jpg


1. Declare variables for storing data
Add a variable miss for recording the timeout state. Execute function time_out (timeout judgement).

Mixly-ctrl-Bingo game 3-code4.jpg

2. Change function start
If bingo is 1 or miss is 1 (it is timeout), the program to reproduce a random number will be executed, reset variable miss, timer1 begins (restart to time).

Mixly-ctrl-Bingo game 3-code5.jpg

3. The content of function time_out.
If timer1 is larger than 3s (it is 3s since the random number was produced, however the numbers hasn’t been aligned), the red LED will flash once and buzzer will buzz lowly once. Set variable miss to 1 (inform function start is timeout).

Mixly-ctrl-Bingo game 3-code6.jpg

4. Function display and bingo needn’t to be changed.

Mixly-ctrl-Bingo game 3-code7.jpg

Technical Specification

Relative Cases

FAQ