Topics

► Games

► Music

► Clocks

► GPS

► Tools

► Tutorials

By processor

► ATtiny85

► ATtiny84

► ATtiny841

► ATtiny2313

► ATtiny861

► ATmega328

► ATmega1284

About Me

About Me

Feeds

RSS feed

Bulls & Cows Game 2

31st March 2015

This article describes an improved version of my Bulls & Cows Game, which thinks of a code for you to guess, and tries simultaneously to guess a code you have thought of.

The circuit is unchanged from the original article; it's based on an ATmega328 or Arduino Uno driving a 6-digit seven-segment display, with a 10-key keypad.

The improvements are as follows:

Sleep function

The program automatically goes to sleep after 30 seconds to preserve the battery, and avoid the need for an on/off switch. Press the "*" key to wake up from sleep.

The current consumption during sleep is less than 2µA, a negligible drain on the battery. I power the prototype from a 40mAh 3.7V Lipo battery fitted under the keypad.

Improved play

The original program averaged about 6.4 turns to guess the player's number. This new version of the program improves this to about 6.1 turns by making the first two guesses use a random selection of eight of the possible digits. It achieves this using an array Mix[] which contains a jumbled list of the ten possible digits, and then chooses the first two guesses from these.

Games won

At the end of each game the program displays the number of games won by the human and computer; for example, if the human has won 15 games and the computer has won 12 it displays:

h15.c12

Give up

To give up trying to guess the computer's code you can press "#" when the "----" prompt is shown. The computer's code is displayed, and the totals of the games won are reset to 0. The "#" key still also has its original function of allowing you to clear an entered number.

Using the 8MHz internal clock

You can make the game play faster by using the internal 8MHz clock rather than the default 1MHz clock. To do this first add the following lines to the boards.txt file in your Arduino application:

##############################################################
atmega328-8.name=ATmega328p (internal 8 MHz clock)
atmega328-8.bootloader.low_fuses=0xe2
atmega328-8.bootloader.high_fuses=0xd9
atmega328-8.bootloader.extended_fuses=0x07
atmega328-8.upload.maximum_size=32768
atmega328-8.build.mcu=atmega328p
atmega328-8.build.f_cpu=8000000L
atmega328-8.build.core=arduino
atmega328-8.build.variant=standard

This adds an ATmega328p (internal 8 MHz clock) option to the Boards menu. Select this and choose Burn Bootloader to set the fuses. Then upload the program to the processor in the usual way.

For information about uploading the program see the original article: Bulls & Cows Game.

Here's the new version of the program: Bulls & Cows Program with Sleep.


blog comments powered by Disqus