6.6 Guess Number¶
Guessing Numbers is a fun party game where you and your friends take turns inputting a number (0~99). The range will be smaller with the inputting of the number till a player answers the riddle correctly. Then the player is defeated and punished. For example, if the lucky number is 51 which the players cannot see, and the player 1 inputs 50, the prompt of number range changes to 50~99; if the player 2 inputs 70, the range of number can be 50~70; if the player 3 inputs 51, he or she is the unlucky one. Here, we use IR Remote Controller to input numbers and use LCD to output outcomes.
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
ITEMS IN THIS KIT
3 in 1 Starter Kit
You can also buy them separately from the links below.
In this example, the wiring of LCD1602 and infrared receiving module is as follows.
You can open the file
6.6.guess_number.inounder the path of
Or copy this code into Arduino IDE 1/2.
IRremote librariesare used here, you can install them from the Library Manager.
After the code is successfully uploaded, the welcome characters will appear on the LCD1602. Now press the number according to the range prompt on the screen, the display will get smaller and smaller unless you guess that lucky number.
If the code and wiring are fine, but the LCD still does not display content, you can turn the potentiometer on the back to increase the contrast.
How it works?
In order to make the number guessing game become vivid and funny, we need to achieve the following functions:
The lucky number will be displayed when we start and reset the game, and the number range prompt is reset to 0 ~ 99.
LCD will display the number being input and the number range prompt.
After inputting two digits, there appears result judgment automatically.
If you input a single digit, you can press the CYCLE key (the key at the center of the Controller) to start the result judgment.
If the answer is not guessed, the new number range prompt will be displayed (if the lucky number is 51 and you enter 50, the number range prompt will change to 50~99).
The game is automatically reset after the lucky number is guessed, so that the player can play a new round.
The game can be reset by directly pressing the POWER button (the button in the upper left corner).
In conclusion, the work flow of the project is shown in the flow chart.