Bingo Game Machine 01

From Microduino Wiki
Revision as of 05:29, 24 March 2017 by Zhangfengfeng (talk) (Created page with "{| style="width: 1000px;" |- | ==Overview== 600px|center Implement the basic display function of the game machine: display a random number...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Overview

Anywhere Bingo game 1.jpg

Implement the basic display function of the game machine: display a random number on the first line of OLED; display numbers 1-6 on the second line, which can be controlled to roll with a potentiometer; display the score on the third line.

Rule

Anywhere Bingo game 1 rule.jpg

Module List

Module

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

Other Equipment

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

Module Setup

Setup

Anywhere Bingo game 1-step.jpg
  • Assemble modules and sensors together:
    • Stick the red core module, battery base, OLED and green Hub together;
    • 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.

Programming

Required Program Blocks

Programming Thought

Declare variables to save data, and write function start to produce random numbers, producing one number each time; write function display to display on OLED, displaying the game interface on OLED. At last, run all functions.

Mixly-ctrl-Bingo game 1.jpg

Start to Program

1. Declare variables for storing random numbers and scores
Variable a is for storing random numbers and variable score is for storing scores.

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


2. Write function start for producing random numbers
Produce a random number between 1-6 and save it in a.

Mixly-ctrl-Bingo game 1-code1.jpg

3. Write function display to display on OLED
Random number a is displayed on the first line of OLED “1 2 3 4 5 6” is displayed on the second line and the x coordinate is the value of the potentiometer. SCORE:score (variable for scores) is displayed on the third line

Mixly-ctrl-Bingo game 1-code2.jpg


4. Execute fucntions
Execute “start” and “display” two functions. Pay attention to that functions should be put below the declarations.

Mixly-ctrl-Bingo game 1-code3.jpg




Test the result
After upload, the random number displayed on the first line of OLED is changing, “1 2 3 4 5 6” is displayed on the second line, and SCORE:0 is displayed on the third line. “1 2 3 4 5 6” on the potentiometer moves OLED quickly.

Anywhere Bingo game 1.jpg



Q: The width of “1 2 3 4 5 6” is only 90 pixels, the value of the potentiometer is 0-1023, so it is difficult to control to align numbers, how to solve that?
A: You can restrain the range of the movement with map program block.

  • Map the value of the potentiometer from 1023-0 to 0-90 (it is 90 on left most, and it is 0 on right most), store the result in b.
  • Set the x coordinate of numbers on the second line to 60-b (because the x coordinate of the random number on the first is 60, when the potentiometer is turned to left most, number 6 on the second number is aligned to the random number; when the potentiometer is turned to right most, the x coordinate of the numbers on the second line is also 60, aligned to number 1).
Mixly-ctrl2-Bingo game 1.jpg


Variable b is for storing the random number. Function start is not changed. Change the content of function display. Map the value of the rotation potentiometer from 1023-0 to 0-90 (it is 0 on left most, and it is 90 on right most), store the result in b. Set the x coordinate of numbers on the second line to 60-b (because the x coordinate of the random number on the first line is 60, when b is 0, the x coordinate of numbers on the second line is also 60, it is just aligned to 1).

Mixly-ctrl-Bingo game 1-code4.jpg

Technical Specification

Relative Cases

Bingo Game Machine 02 Bingo Game Machine 03 Bingo Game Machine 04 Bingo Game Machine 05

FAQ